How can I convert my Java program to an .exe file?

If I have a Java source file (*.java) or a class file (*.class), how can I convert it to a .exe file?

I also need an installer for my program.


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.

JSmooth

(EDIT: Last release was in 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.

JexePack

(EDIT: Shareware: Last updated in 08/29/2013 version-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.

LaunchAnywhere

(EDIT: Commercial with Free Trial, Last version is from 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.

See also for reference Convert Java to EXE: Why, When, When Not and How


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.


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?"

链接地址: http://www.djcxy.com/p/71576.html

上一篇: 什么是存储过程?

下一篇: 我怎样才能将我的Java程序转换为.exe文件?