executable wrapper : Java Glossary
- executable wrapper
A utility that takes a Java jar file and bundles in inside a Windows exe file to give the illusion the program in
a C utility. It still needs a JVM (Java Virtual Machine)
to work. It is not the same as a native
compiler. There are a number of variations:
Creating an EXE file
Here are eight ways to get what acts like a Java executable file:
AOT (Ahead Of Time) compilation
Use an AOT native compiler. This
is the only method that gives you a true machine code executable. You may still have to distribute some DLLs (Dynamic Link Libraries)
or the JRE (Java Runtime Environment) along with your executable. Examples are JET and gcj. This the only technique mentioned here that speeds up execution. The other techniques are
kludges to make Java look like a familiar exe file, without truly being one. See the
native compiler entry for a discussion of the advantages and disadvantages
of true native compilation.
Set up a shortcut with the appropriate java.exe command to load the class.
Bundle your classes in a jar with the Main-Class
attribute. Set up an association for *.jar to
make it executable.
Write yourself a tiny C kicker program that exec’s
a Java command to load your class. Assuming the jar file Foo.jar with main class
Bar, here how to make a Foo.exe tiny kickoff program.
Compile the following program foo.c to foo.exe:
Self Contained Kickers
If you want to play really strange games, concatenate the jar file onto the end of your foo.exe kicker, and put the EXE file on the classpath where you would normally need to place
foo.jar. This way you can distribute but a single file, albeit uncompressed.
Reputedly java.exe will happily treat this combo as a standard jar. Executing
the foo.exe just ignores the jar tacked on the end, e. g. In this case your
custom foo.c kicker code will look like this:
rename foo.exe littlefoo.exe
copy /b littlefoo.exe + foo.jar foo.exe
You only need distribute foo.exe.
Use the InstallAnywhere NOW installer (or other installer). It uses a standard
platform-dependent EXE kickoff file for a standard interpreted
platform-independent Java application packaged in a jar file.
The Microsoft SDK (Software Development Kit) for Java included a tool called jexegen which turned your *.class file(s) into an *.exe file. It didn’t compile them or
convert them to machine code; it just stuffed the contents of the *.class files into
the *.exe file along with some code to pass those bytecodes to the MS JVM to be
interpreted. The resulting exe files needed access to the Microsoft JVM to work, unlike true native
*.exe files which are standalone and written in machine code.
Though Microsoft’s Jexegen and Webgain
Café and Sun’s J2Exe are gone, there are other programs that use the similar wrapping
Java Web Start
Distribute using Java Web Start. Users can click on menu or desktop items to
kick off pure java Programs.