如果我有Java源文件(*.java)或类文件(*.class),如何将其转换为.exe文件?

我还需要一个安装程序。


当前回答

你可以用下面的代码创建一个批处理文件:

start javaw -jar JarFile.jar

并使用任何。bat到。exe转换器将。bat转换为。exe。

其他回答

Launch4j

Launch4j is a cross-platform tool for wrapping Java applications distributed as jars in lightweight Windows native executables. The executable can be configured to search for a certain JRE version or use a bundled one, and it's possible to set runtime options, like the initial/max heap size. The wrapper also provides better user experience through an application icon, a native pre-JRE splash screen, a custom process name, and a Java download page in case the appropriate JRE cannot be found. – Launch4j's website

I can be forgiven for being against converting a java program to a .exe Application and I have My reasons. the Major one being that a java program can be compiled to a jar file from A lot of IDE's. When the program is in .jar format, it can run in Multiple Platforms as opposed to .exe which would run Only in very limited Environment. I am for the Idea that Java Programs shoudl not be converted to Exe unless it is very neccesary. One can always write .bat files that runs the Java program while it is a jar file.

如果真的有必要将其转换为exe, Jar2Exe转换器可以默默地完成,也可以附加与主应用程序一起编译的库。

Java项目被导出为Jar可执行文件。当你想做一个java项目的。EXE文件,你可以做的是“转换”JAR到EXE(我说,我把引号之间转换,因为不是完全这样)。

从intelij你将只能生成罐子

尝试下面的例子:https://www.genuinecoder.com/convert-java-jar-to-exe/

你可以用Janel。最后一个是作为应用程序启动器或服务启动器(可从4.x获得)。

最新的Java Web Start已得到增强,以支持良好的脱机操作以及“本地安装”。这是值得研究的。

EDIT 2018: Java Web Start不再与最新的JDK绑定。甲骨文正在推动一种“使用封闭的JRE在本地部署应用程序”的模式。