This application accepts .groovy scripts or .jar files and generates Windows executable files. This application was written in Groovy and wraps Launch4j, turning it into an easy-to-use command line application.
- If you have a .groovy script that you are planning to run on a Windows machines that only has Java installed
- If you have an executable .jar and need to run it with a specified heap size, but don't want to have to include a .bat file just to set it
- If you are planning on running either a .groovy script or a .jar file on a Windows machine that has Java installed, but does not have the PATH configured correctly or is missing the JAVA_HOME system environment variable
- If you have a .groovy script or a .jar file that executes as a GUI application and want to have a native Windows splash screen display until their application loaded, or have that GUI application treated like a native Windows GUI application
- If you are looking for a tool to integrate into your build process that will generate Windows executable files from .jar or .groovy files
Although g2exe only exposes a subset of Launch4j's features, it also adds support for .groovy scripts and for a wider range of splash image formats. Executable files created by g2exe will automatically resolve Java's installation directory of the PC it's running on (and handle the case when there isn't one).
- The script is loaded into memory by g2exe
- The script's classes are loaded as an AST (abstract syntax tree) and scanned to determine the appropriate main-method
- The script is compiled into a .jar file
- The appropriate Launch4j XML is generated
- Launch4j is called with the generated XML
- The appropriate Launch4j XML is generated
- Launch4j is called with the generated XML
TIP: If your application is a gradle application, you can use the gradle task 'buildJar' in build-executable.gradle to generate an all-in-one jar for your application (be sure to omit the line containing from('gradle.properties', 'LICENSE.txt', '/licenses')
).
The resolution of the java installation directory is done via registry scanning, meaning even java installations to custom directories will be found. When an executable generated by Launch4j runs, it scans the registry for an acceptable JRE version. If one is found, the application utilizes it for execution. If one is not found, an error message appears with a link to the Java Download Page.
Simply download the latest g2exe build.
Alternatively, you could build g2exe yourself:
- Clone the repository
- Navigate to the repository's directory
- Set the java5Home variable in gradle.properties to a valid Java 5 JDK
- Execute:
gradlew buildExe
If the gradle task buildExe
was successful, g2exe.exe will be created on your desktop. You can override this behavior by manipulating the arguments passed into buildExe
in build-executable.gradle.
Add g2exe.exe to your system's path or navigate to its directory and run:
g2exe -f file
where file
is the path (absolute or relative) to the .groovy script or .jar file you want to convert to an executable. This is the minimum required input to run g2exe.
g2exe supports setting:
- Minimum acceptable JRE version
- Application type (console or GUI)
- Application splash screen
- Executable file icon
- The destination directory
- The temporary directory used for g2exe resources
- The JVM initial heap size
- The JVM maximum heap size
For more information on the available parameters, or their default values, run:
g2exe --help
- If the flag
--console
is provided to g2exe, the executable created will operate like a native Windows command line program: opening a command prompt window if one isn't open and printing output to the console. - If the flag
--gui
is provided to g2exe, the executable created will operate like a native Windows GUI program: not opening a command prompt window, and not printing output to the console (this flag also allows the use of a splash screen via--splash <image-file>
)
This application cannot handle scripts which use @Grab
.
All credit for the Launch4j source code goes to Grzegorz Kowal.
This application has been released under the MIT License (MIT).