Java applet 作为独立的 Windows 应用程序?
我有一个只能在 Windows 上运行的 Java 小程序。 (它使用第 3 方 COM 对象;它不是跨平台的。)
有没有办法在 Windows 上将 Java 小程序作为独立应用程序运行?
I have a Java applet that is meant to run only on Windows. (It uses a 3rd party COM object; it is not cross-platform.)
Is there a way to run a Java applet as a stand-alone application on Windows?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
虽然您当然可以运行它,但是 Java 作为应用程序运行的方式与作为 applet 运行的方式之间存在细微的差异。一个从 init 方法开始,另一个从 main 方法开始,启动的线程和事件队列关系有点不同。
这里有一些来自 Sun 的文档,介绍如何执行此操作。如果您使用 JApplet,情况会略有不同,但想法是相同的。
Although you can certainly run it, there are subtle differences between how Java runs as an application vs. how it runs as an applet. One starts with an init method, the other starts with a main method, and the threading and event queue relationship to startup are a bit different.
Here is some documentation from Sun on how to do it. If you are using JApplet things change slightly, but the idea is the same.
Java applet 通常没有 main 方法。他们依赖网络浏览器来启动。
不过,您可以创建一个具有 main 方法的新类,并简单地调用小程序的 init() 和 start() 方法。
您可以查看此以更好地理解小程序的生命周期。
Java applets usually don't have a main method. They rely on the webbrowser to be launched.
It is possible though that you create a new class which have a main method and simple call the init() and start() method of the applet.
You may take a look at this to understand better the life cycle of the applets.
我想 appletviewer 可能是一个选项。它是 JDK 中包含的实用程序。
I suppose the appletviewer could be an option. It is a utility included in the JDK.
JDK 有一个
appletviewer
小程序启动器。它在 JRE 中不可用,并且其行为可能与插件略有不同。如果提供了适当的 JNLP 文件,小程序也可以从 WebStart 运行。
The JDK has an
appletviewer
applet launcher. It is not available in the JRE and its behaviour may be slightly different from the PlugIn.Also applets can be run from WebStart if an appropriate JNLP file is provided.
如果“applet”指的是独立的命令 shell Java 程序,则一个简单的批处理文件就足够了:
将大括号
{{...}}
中的项目替换为适合您的应用程序的设置。如果一切都定义正确,双击文件资源管理器窗口中的批处理文件名将执行您的 Java 类。If by "applet" you mean a stand-alone command shell Java program, a simple batch file should suffice:
Replace the items enclosed in braces
{{...}}
with settings appopriate for your application. If everything is defined correctly, double-clicking the batchfile name in a file explorer window will execute your Java class.