简体   繁体   English

Java applet作为独立的Windows应用程序?

[英]Java applet as stand-alone Windows application?

I have a Java applet that is meant to run only on Windows. 我有一个Java小程序,只能在Windows上运行。 (It uses a 3rd party COM object; it is not cross-platform.) (它使用第三方COM对象;它不是跨平台的。)

Is there a way to run a Java applet as a stand-alone application on Windows? 有没有办法在Windows上将Java applet作为独立应用程序运行?

Although you can certainly run it, there are subtle differences between how Java runs as an application vs. how it runs as an applet. 尽管您当然可以运行它,但Java作为应用程序运行的方式与作为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. 一个以init方法开始,另一个以main方法开始,与启动的线程和事件队列关系有点不同。

Here is some documentation from Sun on how to do it. 以下是 Sun提供的有关如何操作的文档 If you are using JApplet things change slightly, but the idea is the same. 如果你正在使用JApplet,那么事情就会略有改变,但这个想法是一样的。

Java applets usually don't have a main method. Java applet通常没有main方法。 They rely on the webbrowser to be launched. 他们依靠webbrowser发布。

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. 虽然您可以创建一个具有main方法的新类,并且可以简单地调用applet的init()和start()方法。

You may take a look at this to understand better the life cycle of the applets. 您可以看一下这个,以更好地了解applet的生命周期。

I suppose the appletviewer could be an option. 我认为appletviewer可以是一个选项。 It is a utility included in the JDK . 它是JDK中包含的实用程序。

The JDK has an appletviewer applet launcher. JDK有一个appletviewer applet启动器。 It is not available in the JRE and its behaviour may be slightly different from the PlugIn. 它在JRE中不可用,其行为可能与PlugIn略有不同。

Also applets can be run from WebStart if an appropriate JNLP file is provided. 如果提供了适当的JNLP文件,也可以从WebStart运行applet。

If by "applet" you mean a stand-alone command shell Java program, a simple batch file should suffice: 如果“applet”是指一个独立的命令shell Java程序,那么一个简单的批处理文件就足够了:

@rem MyApp.bat
@echo off
set JVM={{path where java.exe is located}}
set FLAGS={{optional JVM flags}}
set JARFILE={{location of your jarfile}}
%JVM%\java %FLAGS% -cp %JARFILE% {{Package}}.{{Class}} {{args...}}

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. 如果一切都已正确定义,则双击文件资源管理器窗口中的批处理文件名将执行Java类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM