If I have a Java source file (*.java) or a class file (*.class), how can I convert it to a .exe file?
如果我有一个Java源文件(*.java)或一个类文件(*.class),那么如何将它转换为.exe文件呢?
I also need an installer for my program.
我还需要一个程序的安装程序。
13 个解决方案
#1
279
Some options:
一些选项:
Executable Jar File
See also Distributing your Application as an executable JAR file and the Oracle docs on how to create a jar file that can be executed with a double-click on Windows.
还可以将您的应用程序分发为可执行的JAR文件和Oracle文档,关于如何创建可以在Windows上双击的JAR文件。
JSmooth
(EDIT: Last release was in 2007)
(编辑:上次发布是在2007年)
JSmooth is a Java Executable Wrapper. It creates native Windows launchers (standard .exe) for your java applications. It makes java deployment much smoother and user-friendly, as it is able to find any installed Java VM by itself.
JSmooth是一个Java可执行包装器。它为您的java应用程序创建原生的Windows launchers(标准.exe)。它使java部署更加流畅和友好,因为它可以自己找到任何安装的java VM。
JexePack
(EDIT: Shareware: Last updated in 08/29/2013 version-8.4)
(编辑:共享软件:最后更新于08/29/2013版本-8.4)
JexePack is a command line tool (great for automated scripting) that allows you to package your Java application (class files), optionally along with its resources (like GIF/JPG/TXT/etc), into a single compressed 32-bit Windows EXE, which runs using Sun's Java Runtime Environment. Both console and windowed applications are supported.
JexePack是一种命令行工具(用于自动编写脚本),它允许您将Java应用程序(类文件)和它的资源(如GIF/JPG/TXT/etc)打包成一个单独的32位窗口EXE,它使用Sun的Java运行时环境运行。支持控制台和窗口应用程序。
LaunchAnywhere
(EDIT: Commercial with Free Trial, Last version is from 2012)
(编辑:免费试用,最新版本为2012年)
A LAX Executable is an executable file that is used to launch a Java application on any LaunchAnywhere-compatible platform. Currently, InstallAnywhere creates LaunchAnywheres on Windows 95/98/NT/2000/Me, Solaris, Linux, and Mac OS X. LaunchAnywhere enables end-users to double-click on an icon (Windows or Mac OS X) or type a single command (UNIX) to start a Java application.
松散的可执行文件是一个可执行文件,用于在任何可兼容的平台上启动Java应用程序。目前,InstallAnywhere在windows95 /98/NT/2000/Me、Solaris、Linux和Mac OS X. LaunchAnywhere创建LaunchAnywheres,允许终端用户双击一个图标(Windows或Mac OS X)或键入一个命令(UNIX)来启动Java应用程序。
See also for reference Convert Java to EXE: Why, When, When Not and How
参见参考转换Java到EXE:为什么,何时,何时不以及如何。
#2
100
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是一个跨平台的工具,用于包装在轻量级Windows本地可执行文件中作为jar分发的Java应用程序。可执行文件可以配置为搜索某个JRE版本或使用绑定的版本,并且可以设置运行时选项,如初始/最大堆大小。包装器还通过应用程序图标提供更好的用户体验,一个本地的pre-JRE启动屏幕、一个自定义进程名称和一个Java下载页面,以防止找到合适的JRE。
#3
32
GCJ: The GNU Compiler for Java can compile Java source code into native machine code, including Windows executables.
GCJ: Java的GNU编译器可以将Java源代码编译成本机代码,包括Windows可执行程序。
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.
尽管不是所有的Java代码都在GCJ中得到支持,特别是GUI组件(参见支持哪些Java API) ?支持有多完整?FAQ的问题)。我还没有使用过GCJ,但是从我在控制台应用程序中所做的有限测试来看,它似乎很好。
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.)
使用GCJ创建独立的可执行文件的一个缺点是,产生的EXE的大小可能相当大。有一次,我在GCJ中编译了一个简单的控制台应用程序,结果是一个大约1 MB的可执行文件(可能有一些我不知道的方法)。另一种选择是可执行压缩程序。
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.)
就开源安装程序而言,Nullsoft脚本安装系统是一个可编写脚本的安装程序。如果您感到好奇,就会有用户提供的示例,说明如何检测JRE的存在,并在不安装所需的JRE时自动安装它。(只是想让你知道,我以前没有用过NSIS。)
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?"
有关使用NSIS安装Java应用程序的更多信息,请查看我对“分发Java应用程序的最佳方式是什么?”的回答。
#4
23
You can try many of the java wrappers out there like JSmooth, JWrapper, and other utilities but you can also make a .bat with the following code:start javaw -jar JarFile.jar
and convert the bat to an exe using any .bat to .exe converter.
您可以尝试许多类似JSmooth、JWrapper和其他实用程序的java包装器,但您也可以使用以下代码创建.bat:启动javaw -jar JarFile。使用任何.bat到.exe转换器将bat转换为exe。
#5
14
We're using Install4J to build installers for windows or unix environments.
我们使用Install4J为windows或unix环境构建安装程序。
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.
它可以很容易地定制到您想要为特殊操作编写脚本的地方,而这些操作不能通过标准的对话来完成。但是,即使我们用它来设置windows服务,我们也只使用标准组件。
- installer + launcher
- 安装程序+发射器
- windows or unix
- windows和unix
- scriptable in Java
- 在Java脚本
- ant task
- ant任务
- lots of customizable standard panels and actions
- 许多可定制的标准面板和操作。
- optionally includes or downloads a JRE
- 可选地包含或下载一个JRE。
- can also launch windows services
- 还可以启动windows服务吗?
- multiple languages
- 多种语言
I think Launch4J is from the same company (just the launcher - no installer).
我认为Launch4J是来自同一家公司(只是启动器——没有安装程序)。
PS: sadly i'm not getting paid for this endorsement. I just like that tool.
遗憾的是,我没有得到这笔背书的报酬。我就是喜欢这个工具。
#6
14
The latest Java Web Start has been enhanced to allow good offline operation as well as allowing "local installation". It is worth looking into.
最新的Java Web Start已经被增强,允许良好的脱机操作以及允许“本地安装”。这是值得研究的。
#8
7
If you need to convert your entire application to native code, i.e. an EXE plus DLLs, there is ExcelsiorJET. I found it works well and provided an alternative to bundling a JRE.
如果您需要将整个应用程序转换为本机代码,即EXE + dll,则有ExcelsiorJET。我发现它很好用,并且提供了一个捆绑JRE的替代方案。
#9
4
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-to-c转换器(例如,JCGO),并将生成的C文件编译为目标平台的本地二进制文件(.exe)文件。
#10
4
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.
我认为launch4j是将java源代码(.java)转换为.exe文件的最佳工具,您甚至可以将jre与它捆绑在一起进行分发,甚至可以将exe打包为iconified。尽管应用程序的大小增加了,但它确保即使用户没有安装jre,应用程序也能完美地工作。它还确保您能够为您的应用程序提供特定的jre,而无需用户单独安装。但不幸的是,java失去了它的重要性。它的多平台支持完全被忽略,最终的应用程序只支持windows。但这并不是什么大不了的事情,如果你只面向windows用户。
#11
4
You can use Janel. This last works as an application launcher or service launcher (available from 4.x).
您可以使用吉娜。最后的工作是应用程序启动程序或服务启动程序(从4.x提供)。
#12
3
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.
可以原谅我反对将java程序转换为.exe应用程序,我有我的理由。主要的一点是,java程序可以从许多IDE中编译到jar文件。当程序处于.jar格式时,它可以在多个平台上运行,而不是只在非常有限的环境中运行的.exe。我的想法是,Java程序不应该被转换为Exe,除非它是非常必要的。一个可以编写。bat文件,它运行Java程序,而它是一个jar文件。
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.
如果真的需要将其转换为exe, Jar2Exe转换器就会这样做,而且还可以附加与主应用程序一起编译的库。
#13
#1
279
Some options:
一些选项:
Executable Jar File
See also Distributing your Application as an executable JAR file and the Oracle docs on how to create a jar file that can be executed with a double-click on Windows.
还可以将您的应用程序分发为可执行的JAR文件和Oracle文档,关于如何创建可以在Windows上双击的JAR文件。
JSmooth
(EDIT: Last release was in 2007)
(编辑:上次发布是在2007年)
JSmooth is a Java Executable Wrapper. It creates native Windows launchers (standard .exe) for your java applications. It makes java deployment much smoother and user-friendly, as it is able to find any installed Java VM by itself.
JSmooth是一个Java可执行包装器。它为您的java应用程序创建原生的Windows launchers(标准.exe)。它使java部署更加流畅和友好,因为它可以自己找到任何安装的java VM。
JexePack
(EDIT: Shareware: Last updated in 08/29/2013 version-8.4)
(编辑:共享软件:最后更新于08/29/2013版本-8.4)
JexePack is a command line tool (great for automated scripting) that allows you to package your Java application (class files), optionally along with its resources (like GIF/JPG/TXT/etc), into a single compressed 32-bit Windows EXE, which runs using Sun's Java Runtime Environment. Both console and windowed applications are supported.
JexePack是一种命令行工具(用于自动编写脚本),它允许您将Java应用程序(类文件)和它的资源(如GIF/JPG/TXT/etc)打包成一个单独的32位窗口EXE,它使用Sun的Java运行时环境运行。支持控制台和窗口应用程序。
LaunchAnywhere
(EDIT: Commercial with Free Trial, Last version is from 2012)
(编辑:免费试用,最新版本为2012年)
A LAX Executable is an executable file that is used to launch a Java application on any LaunchAnywhere-compatible platform. Currently, InstallAnywhere creates LaunchAnywheres on Windows 95/98/NT/2000/Me, Solaris, Linux, and Mac OS X. LaunchAnywhere enables end-users to double-click on an icon (Windows or Mac OS X) or type a single command (UNIX) to start a Java application.
松散的可执行文件是一个可执行文件,用于在任何可兼容的平台上启动Java应用程序。目前,InstallAnywhere在windows95 /98/NT/2000/Me、Solaris、Linux和Mac OS X. LaunchAnywhere创建LaunchAnywheres,允许终端用户双击一个图标(Windows或Mac OS X)或键入一个命令(UNIX)来启动Java应用程序。
See also for reference Convert Java to EXE: Why, When, When Not and How
参见参考转换Java到EXE:为什么,何时,何时不以及如何。
#2
100
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是一个跨平台的工具,用于包装在轻量级Windows本地可执行文件中作为jar分发的Java应用程序。可执行文件可以配置为搜索某个JRE版本或使用绑定的版本,并且可以设置运行时选项,如初始/最大堆大小。包装器还通过应用程序图标提供更好的用户体验,一个本地的pre-JRE启动屏幕、一个自定义进程名称和一个Java下载页面,以防止找到合适的JRE。
#3
32
GCJ: The GNU Compiler for Java can compile Java source code into native machine code, including Windows executables.
GCJ: Java的GNU编译器可以将Java源代码编译成本机代码,包括Windows可执行程序。
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.
尽管不是所有的Java代码都在GCJ中得到支持,特别是GUI组件(参见支持哪些Java API) ?支持有多完整?FAQ的问题)。我还没有使用过GCJ,但是从我在控制台应用程序中所做的有限测试来看,它似乎很好。
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.)
使用GCJ创建独立的可执行文件的一个缺点是,产生的EXE的大小可能相当大。有一次,我在GCJ中编译了一个简单的控制台应用程序,结果是一个大约1 MB的可执行文件(可能有一些我不知道的方法)。另一种选择是可执行压缩程序。
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.)
就开源安装程序而言,Nullsoft脚本安装系统是一个可编写脚本的安装程序。如果您感到好奇,就会有用户提供的示例,说明如何检测JRE的存在,并在不安装所需的JRE时自动安装它。(只是想让你知道,我以前没有用过NSIS。)
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?"
有关使用NSIS安装Java应用程序的更多信息,请查看我对“分发Java应用程序的最佳方式是什么?”的回答。
#4
23
You can try many of the java wrappers out there like JSmooth, JWrapper, and other utilities but you can also make a .bat with the following code:start javaw -jar JarFile.jar
and convert the bat to an exe using any .bat to .exe converter.
您可以尝试许多类似JSmooth、JWrapper和其他实用程序的java包装器,但您也可以使用以下代码创建.bat:启动javaw -jar JarFile。使用任何.bat到.exe转换器将bat转换为exe。
#5
14
We're using Install4J to build installers for windows or unix environments.
我们使用Install4J为windows或unix环境构建安装程序。
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.
它可以很容易地定制到您想要为特殊操作编写脚本的地方,而这些操作不能通过标准的对话来完成。但是,即使我们用它来设置windows服务,我们也只使用标准组件。
- installer + launcher
- 安装程序+发射器
- windows or unix
- windows和unix
- scriptable in Java
- 在Java脚本
- ant task
- ant任务
- lots of customizable standard panels and actions
- 许多可定制的标准面板和操作。
- optionally includes or downloads a JRE
- 可选地包含或下载一个JRE。
- can also launch windows services
- 还可以启动windows服务吗?
- multiple languages
- 多种语言
I think Launch4J is from the same company (just the launcher - no installer).
我认为Launch4J是来自同一家公司(只是启动器——没有安装程序)。
PS: sadly i'm not getting paid for this endorsement. I just like that tool.
遗憾的是,我没有得到这笔背书的报酬。我就是喜欢这个工具。
#6
14
The latest Java Web Start has been enhanced to allow good offline operation as well as allowing "local installation". It is worth looking into.
最新的Java Web Start已经被增强,允许良好的脱机操作以及允许“本地安装”。这是值得研究的。
#7
#8
7
If you need to convert your entire application to native code, i.e. an EXE plus DLLs, there is ExcelsiorJET. I found it works well and provided an alternative to bundling a JRE.
如果您需要将整个应用程序转换为本机代码,即EXE + dll,则有ExcelsiorJET。我发现它很好用,并且提供了一个捆绑JRE的替代方案。
#9
4
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-to-c转换器(例如,JCGO),并将生成的C文件编译为目标平台的本地二进制文件(.exe)文件。
#10
4
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.
我认为launch4j是将java源代码(.java)转换为.exe文件的最佳工具,您甚至可以将jre与它捆绑在一起进行分发,甚至可以将exe打包为iconified。尽管应用程序的大小增加了,但它确保即使用户没有安装jre,应用程序也能完美地工作。它还确保您能够为您的应用程序提供特定的jre,而无需用户单独安装。但不幸的是,java失去了它的重要性。它的多平台支持完全被忽略,最终的应用程序只支持windows。但这并不是什么大不了的事情,如果你只面向windows用户。
#11
4
You can use Janel. This last works as an application launcher or service launcher (available from 4.x).
您可以使用吉娜。最后的工作是应用程序启动程序或服务启动程序(从4.x提供)。
#12
3
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.
可以原谅我反对将java程序转换为.exe应用程序,我有我的理由。主要的一点是,java程序可以从许多IDE中编译到jar文件。当程序处于.jar格式时,它可以在多个平台上运行,而不是只在非常有限的环境中运行的.exe。我的想法是,Java程序不应该被转换为Exe,除非它是非常必要的。一个可以编写。bat文件,它运行Java程序,而它是一个jar文件。
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.
如果真的需要将其转换为exe, Jar2Exe转换器就会这样做,而且还可以附加与主应用程序一起编译的库。