Creating Win32 Applications with jexegen.exe
M. Gallant 10/15/2001
Java is a great development environment, designed to enable rapid generation
of relatively bug-free versatile robust code. For deployment to Win32 platforms, greater performance
and end-user convenience can be achieved by compiling your Java bytecode into
Win32 executable applications (which however still require the MS-JVM installed for
certain Java-specific dlls). The Microsoft utility jexegen.exe, included with
the Microsoft SDK 4 for Java converts
arbitrary Java bytecode class files, and any resource files (images, sound, text, binary ..)
into a self-contained win32 executable .exe file, launchable on any win32 platform
with IE4+ installed.
Procedure for Generating Win32 exe using Jexegen.exe
- Write the Java code. To prevent name-space clashes, use the standard
Java package recommendations.
This is important, as the getResource() method will search within the system
Sample source code.
Note that the getResource() method uses a "relative" name, which implies the
same package name as the class referencing the resource.
- Compile the code with either javac.exe (Sun) or jvc.exe (Microsoft). Ensure that the compiler
executable is on your system path. If there are win32-specific
methods/classes, use jvc. For example, for the source code above, place the source
code in the "current directory" and execute the following:
jvc /d . RandomLogo.java
The /d option will automatically generate the correct directory substructure corresponding
to the package name.
- Put your resources in the same directory as the classes, to ensure that your resources
have the same unique packaging scheme as your Java classes (to prevent resource naming
conflict). You can in fact include your source code, and any other files here as well!
At this stage, you have a typical Java application which could be launched with either of:
- Use jexegen (from the current directory with package subdirectory below it) to generate
the win32 executable:
jexegen /main:com.javascience.msapps.RandomLogo /w /out:randomlogo.exe com/javascience/msapps/*.* flask.res
Note how the com/javascience/msapps/*.* specifies all the files (class, image, source code etc..) be included in
the exe file as resources. The /w switch prevents the console window from appearing. The optional flask.res is
a binary win32 resource file specifying resources for the .exe file, such as a custom icon (see below).
- For software distribution, and integrity verification, digitally sign the win32
executable with a software publishing certificate (code-signing certificate). For example:
signcode -cn "Security Development" -n "Embedded Image demo" -t "http://timestamp.verisign.com/scripts/timstamp.dll" randomlogo.exe
To verify or inspect the signature on the exe file, right click it and select
the Properties/Digital Signatures pane.
- To run the resultant randomlogo.exe file,
just double-click as usual for any win32 application.
Download and run randomlogo.exe
Using a custom icon with the jexegen .exe Java application
A custom desktop icon can be included as a resource with a jexegen-generated application.
This can be done in a number of ways:
(1) Use VC++ 6 to edit the .exe file as a resource and add an icon resource.
(2) Generate and compile a custom stub .exe file with the custom icon (SDK4/Java samples).
(3) Use the rc.exe utility (Resource Compiler) provided with the Windows Platform SDK (doesn't require
the C++ compiler).
The manual approach using the rc.exe Platform SDK utility is now described:
The custom icon image in the file "flask.ico" is now bound into the .exe Java application.