如何将我的Java程序转换为.EXE文件?
如果我有一个Java源文件(*.java)或类文件(*.class),我该如何将其转换为.exe文件?
我还需要一个安装程序的程序。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如果我有一个Java源文件(*.java)或类文件(*.class),我该如何将其转换为.exe文件?
我还需要一个安装程序的程序。
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(16)
javapackager
Javapackager
用JDK船舶运输。它可以使用nativate exe
flag生成.exe文件。winrun4j
winrun4j是开源实用程序。它具有许多功能。
packr
Packr是另一个开源工具。
jsmooth
JSmooth是开源的,具有功能,但它很旧。最后一个版本是在2007年。
jexepack
Jexepack是试用器。生产使用所需的付款,并且使用此工具创建的EXE文件将显示“提醒”而无需付款。此外,最后一个版本是2013年。
installanywhere
installanywhere是一个商业/企业软件包,为基于Java的程序生成安装程序。它可能能够创建.exe文件。
可执行JAR文件
作为.exe文件的替代方案,您可以创建一个JAR文件,双击时自动运行,
有关更多信息,
有关此主题的绝佳信息来源是本文,“ 将java转换为exe - 为什么,何时,何时不及时,”,dmitry leskov,dmitry leskov,
另请参见伴侣页面” ”
javapackager
The
javapackager
utility ships with the JDK. It can generate .exe files with the-native exe
flag, among many other things.WinRun4J
WinRun4J is an open source utility. It has many features.
packr
packr is another open source tool.
JSmooth
JSmooth is open source and has features, but it is very old. The last release was in 2007.
JexePack
JexePack is trialware. Payment is required for production use, and exe files created with this tool will display "reminders" without payment. Also, the last release was in 2013.
InstallAnywhere
InstallAnywhere is a commercial/enterprise package that generates installers for Java-based programs. It's probably capable of creating .exe files.
Executable JAR files
As an alternative to .exe files, you can create a JAR file that automatically runs when double-clicked, by adding an entry point to the JAR manifest.
For more information
An excellent source of information on this topic is this article, "Convert Java to EXE – Why, When, When Not and How", by Dmitry Leskov
See also the companion page "Best JAR to EXE Conversion Tools, Free and Commercial"
lainish4j
Launch4j
gcj:将Java源代码编译到本机机器代码中,包括Windows可执行文件。
虽然并非Java中的所有内容都得到了GCJ的支持,尤其是GUI组件(请参阅
常见问题)。我没有使用GCJ太多,但是从我对控制台应用程序进行的有限测试中,这似乎还不错。
使用GCJ创建独立可执行文件的一个缺点是,所得EXE的大小可能很大。一次,我在GCJ中编制了一个琐碎的控制台应用程序,结果是可执行文件约为1 MB。 (可能有一些我不知道的方法。另一个选择是可执行的压缩程序。)
就开源安装程序而言, nullsoft脚本安装系统是一个脚本安装程序。如果您很好奇,会有用户贡献了示例如果未安装所需的JRE,则会自动安装它。 (只是让您知道,我以前从未使用过NSI。)
有关使用NSIS安装Java应用程序的更多信息,请查看我对问题的回答” 分发Java应用程序的最佳方法是什么?”
GCJ: The GNU Compiler for Java can compile Java source code into native machine code, including Windows executables.
Although not everything in Java is supported under GCJ, especially the GUI components (see
What Java API's are supported? How complete is the support? question from the FAQ). I haven't used GCJ much, but from the limited testing I've done with console applications, it seems fine.
One downside of using GCJ to create an standalone executable is that the size of the resulting EXE can be quite large. One time I compiled a trivial console application in GCJ and the result was an executable about 1 MB. (There may be ways around this that I am not aware of. Another option would be executable compression programs.)
In terms of open-source installers, the Nullsoft Scriptable Install System is a scriptable installer. If you're curious, there are user contributed examples on how to detect the presence of a JRE and install it automatically if the required JRE is not installed. (Just to let you know, I haven't used NSIS before.)
For more information on using NSIS for installing Java applications, please take a look at my response for the question "What's the best way to distribute Java applications?"
您可以使用以下代码制作批处理文件:
并使用任何.EXE转换器将.bat转换为.exe。
You could make a batch file with the following code:
and convert the .bat to an .exe using any .bat to .exe converter.
我们正在使用 install4j 以构建用于Windows或Unix环境的安装程序。
它很容易自定义,直到您想编写脚本以进行标准对话无法完成的特殊操作。但是,即使我们正在使用它来设置Windows服务,我们也只使用标准组件。
我认为启动4J来自同一家公司(只是启动器 - 没有安装程序)。
We're using Install4J to build installers for Windows or Unix environments.
It's easily customizable up to the point where you want to write scripts for special actions that cannot be done with standard dialogues. But even though we're setting up Windows services with it, we're only using standard components.
I think Launch4J is from the same company (just the launcher - no installer).
最新版本的 java-web start 已经增强了以允许良好的离线操作以及允许“本地安装”。值得研究。
但是,截至2018年,Java Web的开始不再与最新的JDK捆绑在一起。 Oracle朝着“用封闭的JRE”模型推向“本地部署您的应用程序”。
The latest version of java-web-start has been enhanced to allow good offline operation as well as allowing "local installation". It is worth looking into.
However, as of 2018 Java Web Start is no longer bundled with the newest JDKs. Oracle is pushing toward a "deploy your app locally with an enclosed JRE" model instead.
从jdk14开始, jpackage @Jay答案中提到的Javapackager 。 Windows版本需要Wix 3.0,使用Java应用程序并构建提供EXE启动器的安装程序非常简单。
它也可以与 jlink 步骤也将通过jpackage隐式运行,但是我更喜欢单独制作JRE映像,因为只有在您更新JDK或在项目中添加新的模块依赖项时才会更改。
Java类的示例主要:
以下是在Windows上构建的示例步骤 - 显然您要设置本地构建环境(Maven / Ant / etc)以重新生产以下内容:
检查它运行:
使用JLink创建一个运行时映像应用程序中使用的模块集:
如果上面有丢失的模块,则应检查JLINK JRE运行时图像可以运行您的应用程序:
使用jpackage生成安装程序,并使用app 62819060>版本- 安装每个重新安装)并打印所有系统属性 - 测试后删除参数“ -xshowsettings:属性:属性”:
运行安装程序:
测试应用程序:
As of JDK14, jpackage replaces
javapackager
mentioned in @Jay answer. The Windows version requires Wix 3.0 and it is fairly straightforward to take a java application and build an installer which provides EXE launcher.It can also be used with jlink to build a cut-down Java runtime image which is bundled with the installer and only contains the set of modules needed to support your application. The
jlink
step will also be run implicitly by jpackage if no runtime is specified, but I prefer to make the JRE image separately as it will only change when you update JDK or add new module dependencies to your project.Example main for Java class:
Here are example steps to build on Windows - obviously you'd set up your local build environment (Maven / ant / etc) to re-produce this:
Check it runs:
Create a runtime image with jlink for the set of modules use by your application:
In case there are missing modules above, you should check the jlink JRE runtime image can run your app:
Use jpackage to generate installer, with app version based on date+hour (this saves on need to un-install every re-install) and to print out all system properties - remove the parameter "-XshowSettings:properties" after testing:
Run the installer:
Test the application:
Imho jsmooth 似乎做得很好。
IMHO JSmooth seems to do a pretty good job.
我要说的是启动4J是将Java源代码(.java)转换为.exe文件的最佳工具
您甚至可以将JRE捆绑在一起以进行分发,甚至可以将EXE塑造出来。
尽管应用程序的大小增加,但即使用户未安装JRE,该应用程序也可以完美地工作。它还可以确保您能够为应用程序提供所需的特定JRE,而无需用户单独安装它。
但不幸的是,爪哇失去了其重要性。它的多平台支持被完全忽略,最终应用仅支持Windows。但这没什么大不了的,如果您仅适合Windows用户。
I would say launch4j is the best tool for converting a java source code(.java) to .exe file
You can even bundle a jre with it for distribution and the exe can even be iconified.
Although the size of application increases, it makes sure that the application will work perfectly even if the user does not have a jre installed. It also makes sure that you are able to provide the specific jre required for your app without the user having to install it separately.
But unfortunately, java loses its importance. Its multi platform support is totally ignored and the final app is only supported for windows. But that is not a big deal, if you are catering only to windows users.
您可以使用 janel 。这最后是应用程序启动器或服务启动器(可从4.x获得)。
You can use Janel. This last works as an application launcher or service launcher (available from 4.x).
另外,您可以使用一些Java-to-C转换器(例如, jcgo )并编译生成的C将目标平台的本机二进制文件(.EXE)文件文件。
Alternatively, you can use some java-to-c translator (e.g., JCGO) and compile the generated C files to a native binary (.exe) file for the target platform.
可以原谅我不反对将Java程序转换为.EXE应用程序,而我有理由。主要的是,可以将Java程序从许多IDE中汇编成Jar文件。当程序以.jar格式为.JAR时,它可以在多个平台中运行,而不是在非常有限的环境中运行的.EXE。我的想法是,Java程序shoudl不会转换为EXE,除非它非常必要。人们总是可以写入.BAT文件,该文件是JAVA程序时运行JAVA程序的文件。
如果将其转换为EXE确实是必要的,JAR2EXE转换器会默默地执行此操作,并且还可以将库与主应用程序一起编译在一起。
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.
if it is really neccesary to convert it to exe, Jar2Exe converter silently does that and one can also attach Libraries that are compiled together with the Main Application.
您可以使用 jar2exe 将JAR转换为EXE。但是,您需要购买该软件。如果您需要开源软件,我建议 jsmooth 。
You can convert jar to exe using jar2exe. However you need to purchase the software. If you need a open source software i would suggest JSmooth.
graalvm
这对我来说是一个足够好的软件,我早些时候已经使用过。
该软件可以将Java项目编译为本机可执行文件,也可以将JAR文件转换为本机可执行文件,这比我在网上找到的任何转换器要好得多,因为它可以更快,更顺畅。
GraalVM
This is a good enough software for me, i have used it earlier.
This software can compile java projects to native executables, it can also convert jar files to native executables, this is much better than any converter i found online as it works faster and smoother.
谨慎说明:自这个问题首次提出以来,随着包装和部署的变化发生了很多变化。给出的大多数答案甚至都没有拼图(Java 9+)。
如果目标是创建特定的软件包,则在Oracle Docs Java 17 包装工具用户指南。本指南包括
jpackage
工具的文档,该工具允许人们为Linux,MacOS和Windows创建特定于平台的软件包。我认为特定于Windows的说明应包括到达.EXE文件,因为这仍然是Windows用户安装和运行应用程序的最熟悉的方式。我自己的个人经验创建EXE(在iTch.io上出售)是在 Java平台,标准版Deployment Guide 中,其中包括使用工具Inno设置5 。该文档较早,适用于Java 9。 #jsdpg600“ rel =“ nofollow noreferrer”>在这里作为第一步,我使用
jlink
来制作一个独立的软件包。在我第一次争吵时,我无法弄清楚如何获得jpackage
与我的模块化程序一起工作。但是,既然拼图已经存在了几年,那么jpackage
现在可能更容易使用,这将是我可能为Windows用户发布的下一个Java应用程序的首选。Cautionary note: Much has changed with packaging and deployment since this question was first asked. Most of the answers given are not even current with JIGSAW (Java 9+).
If the goal is to create OS specific packages, information is provided in Oracle Docs Java 17 Packaging Tool User Guide. This guide includes documentation for the
jpackage
tool, which allows one to create platform-specific packages for Linux, macOS and Windows. I assume the Windows-specific instructions should include arriving at an .exe file, since that remains the most familiar way for Windows users to install and run applications.My own personal experience creating an exe (for sale on itch.io) was with the Java Platform, Standard Edition Deployment Guide, which included making use of the tool Inno Setup 5. This documentation is older, is for Java 9. The section directly pertaining to .exe packaging is located here As a first step, I used
jlink
to make a self-contained package. At the time I was first wrangling with this, I was unable to figure out how to getjpackage
to work with my modular program. But now that Jigsaw has been around for several years,jpackage
is now likely much easier to use, and would be my first choice for the next Java app I might publish for Windows users.Java项目被导出为JAR可执行文件。当您想做一个Java项目的.EXE文件时,您可以做的是将罐子“转换”到exe(我指出我在引号转换之间放置了converts convert,因为这不是完全如此)。
从Intelij,您将只能生成罐子,
然后按照下一个示例尝试: https://www.genuinecoder.com/convert-java-jar-jar-to-exe/
Java projects are exported as Jar executables. When you wanna do a .exe file of a java project, what you can do is 'convert' the JAR to EXE (i remark that i putted between quotes convert because isn't exactly this).
From intelij you gonna be able to generate only the jar
Try following the next example : https://www.genuinecoder.com/convert-java-jar-to-exe/