如果我有Java源文件(*.java)或类文件(*.class),如何将其转换为.exe文件?
我还需要一个安装程序。
如果我有Java源文件(*.java)或类文件(*.class),如何将其转换为.exe文件?
我还需要一个安装程序。
当前回答
你可以用Janel。最后一个是作为应用程序启动器或服务启动器(可从4.x获得)。
其他回答
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转换器可以默默地完成,也可以附加与主应用程序一起编译的库。
更新:GCJ死了。它于2016年正式从海湾合作委员会项目中移除。甚至在此之前,它实际上已经被废弃了7年之久,而且无论如何,它都不够完整,无法作为可行的Java实现替代方案。 去找另一个Java AOT编译器。
GCJ: GNU Java编译器可以将Java源代码编译成本机机器码,包括Windows可执行文件。
虽然GCJ并不支持Java中的所有内容,特别是GUI组件(请参阅GCJ 支持哪些Java API ?支持有多完整?FAQ中的问题)。我很少使用GCJ,但从我对控制台应用程序所做的有限测试来看,它似乎还不错。
使用GCJ创建独立可执行文件的一个缺点是,生成的EXE的大小可能相当大。有一次我在GCJ中编译了一个简单的控制台应用程序,结果是一个大约1 MB的可执行文件(可能有我不知道的方法)。另一个选择是可执行的压缩程序。)
在开源安装程序方面,Nullsoft Scriptable Install System是一个可脚本的安装程序。如果您感到好奇,可以参考用户提供的示例,了解如何检测JRE的存在并在未安装所需JRE时自动安装JRE。(只是想让你知道,我以前没有用过NSIS。)
有关使用NSIS安装Java应用程序的更多信息,请参阅我对“分发Java应用程序的最佳方式是什么?”这个问题的回答。
我们正在使用Install4J为windows或unix环境构建安装程序。
它很容易定制,直到您想要为标准对话框无法完成的特殊操作编写脚本。但是即使我们用它来设置windows服务,我们也只是使用标准组件。
安装程序+启动程序 Windows或Unix Java脚本 ant任务 大量可定制的标准面板和操作 可选地包括或下载JRE 还能启动Windows服务吗 多种语言
我认为Launch4J来自同一家公司(只有启动器-没有安装程序)。
PS:很遗憾我没有得到这个代言的报酬。我只是喜欢那个工具。
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
您可以使用jar2exe将jar转换为exe。但是你需要购买软件。如果你需要一个开源软件,我会建议JSmooth。