Eclipse 中具有依赖项的 Applet

发布于 2024-11-05 03:26:35 字数 367 浏览 1 评论 0原文

一般来说,我对 eclipse 和 java 相当陌生,所以我确信这是非常基本的,但我找不到任何能指引我正确方向的东西。

如何在 Eclipse 中运行/测试需要一些第 3 方 jar 的小程序?

我有一个应用程序与我的依赖 jar(具体来说是 JOGL)一起运行,效果很好。我可以运行一个示例小程序。但我无法运行需要 JOGL jar 的小程序。我知道将其嵌入到网页中的 HTML 需要引用依赖项,但是由于它不是标准 java 工具包的一部分,我如何告诉 eclipse 去哪里查找呢?

我的最终需要是将应用程序/小程序嵌入网页中(不是从中启动,而是作为页面上的内联对象运行。我还没有尝试嵌入任何东西,但也许有一个角落我可以切到那里,我根本不必担心小程序结构......

I'm fairly new to eclipse and java in general, so I'm sure this is pretty basic, but I can't find anything that points me in the right direction.

How do I run/test an applet in Eclipse that requires some 3rd party jars?

I have an application running with my dependent jars (JOGL to be specific) fine. And I can run a sample applet. But I can't run an applet that requires the JOGL jars. I understand the HTML for embedding it in a web page needs to reference the dependencies, but how do I tell eclipse where to look since it's not part of the standard java kit?

My ultimate need is to embed an application/applet IN a web page (not launched from, but running as in inline object on the page. I haven't gotten as far as trying to embed anything yet, but perhaps there's a corner I can cut there and I won't have to worry about the applet structure at all...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦幻之岛 2024-11-12 03:26:35

您可以采用与具有 main() 方法的程序相同的方式进行操作。转到属性 -->构建路径 -->罐子。在那里添加您的第三方罐子,程序应该会拾取它们。

首先创建一个虚拟的第三方 jar,它有一个名为 hello() 的方法。您可以通过右键单击该项目并将其导出到 jar 来将该项目转换为 jar。非常简单。该第三方 jar 的代码非常简单。

package test;

public class ThirdParty {
    public String hello(){
        return "Hello from third party called!!";
    }
}

之后,创建一个名为 HelloApplet 的简单小程序。它所拥有的只是显示一个小程序,然后调用我们的第三方 jar。将 jar 添加到 eclipse 中,如下面的屏幕截图所示。

在此处输入图像描述

这个 TestApplet 的源代码非常非常简单,如下所示。

import javax.swing.JApplet;

import test.ThirdParty;

public class TestApplet extends JApplet{
    public void init(){
        this.setSize(400, 400);
        this.setVisible(true);

        ThirdParty tParty = new ThirdParty();
        System.out.println(tParty.hello());
    }

}

右键单击该文件并选择作为 Applet 运行。就这样吧!您会看到您的小程序和消息也打印在控制台上!有什么疑问可以在评论区提问,我会尽力帮助!

You do the same way as you do for a program having a main() method. Goto properties --> Build path --> Jars. Add your third party jars there and the program should pick them up.

First create a dummy third party jar which has a single method called hello(). You can convert that project into a jar by right clicking on the project and exporting it to a jar. Its very simple. The code for that third party jar is very simple.

package test;

public class ThirdParty {
    public String hello(){
        return "Hello from third party called!!";
    }
}

After this, create a simple applet called HelloApplet. All it has is just displaying an applet and in turn calling our third party jar. Adding the jar to the eclipse is shown as in the below screenshot.

enter image description here

The source code for this TestApplet is very very simple as shown below.

import javax.swing.JApplet;

import test.ThirdParty;

public class TestApplet extends JApplet{
    public void init(){
        this.setSize(400, 400);
        this.setVisible(true);

        ThirdParty tParty = new ThirdParty();
        System.out.println(tParty.hello());
    }

}

Right click on the file and select Run as Applet. There you go! You would both see your applet and the message getting printed on the console as well! Any doubts you have, ask in comments section, I will try to help!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文