Jexegen Reference |
![]() Previous |
![]() About Tools |
![]() Next |
The jexegen tool is used to create Microsoft® Win32® executables from Java applications. The class files for the application are bound into the executable, and do not need to exist anywhere else on the drive. Note that the Microsoft VM for Java is required to run programs generated by the jexegen tool.
You must specify on the jexegen command line what class files you want to include and the name of the main class file. For example, say you have a Java application that consists of three class files—A.class, B.class, and C.class—and that class A contains the application's entry point (the main method). To generate an executable, you would run the following command from the directory that contains the class files.
jexegen /main:A /out:MyApp.exe A.class B.class C.class
In this case, the jexegen tool creates the file MyApp.exe, which contains your Java application.
JEXEGEN [options] [@command file] files
The options are as follows:
/MAIN:classname | (Required) Sets the name of the main class file. This class must contain
the public static method main. The name specified on the
command line must be the same as the class's internal name;
it is case-sensitive and you must separate package names with periods.
For example, if you normally run your application with the command line: view Foo.bar then the appropriate switch for jexegen would be: /main:Foo.bar |
/NOMAIN | Specifies that you do not want to specify a main class file. This option is useful only in conjunction with the /RAW or /BINDTO option. |
/BASE:dir | Changes the base directory used to determine package names of specified class files. When used with the /RAW or /BINDTO option, this option specifies the base directory to which file operations are relative. By default, package names and file operations are determined relative to the current directory. If used more than once on the command line, all /BASE options are relative to the original (current) directory. |
/OUT:filename | Specifies the name of the output file. |
/R | Indicates that jexegen should recurse into subdirectories when searching for the specified class files. By default, subdirectories will not be searched. |
/R- | Used to turn off subdirectory recursion. Only useful if
the /R option has already been used.
For example, consider the following partial command line: /r Foo*.class /r- Bar*.class This indicates that jexegen should find all class files matching Foo*.class in the current directory and all subdirectories, and all files matching Bar*.class in the current directory only. |
/V | Provides more detailed output. |
/W | The generated executable will not have an associated console window. This option will be useful only for graphical applications. |
/BINDTO:stub | Specifies the executable (.exe) or dynamic-link library (DLL) to bind the class resources to. |
/RAW | Saves resource data to a file and does not generate an executable. The data file generated is of the appropriate format to be used with the IJavaExecute2::SetClassSource method. |
You must take special care to preserve package names when using the jexegen tool. The package names of the classes to be bound into the executable are determined by the directories in which those class files are located. So, therefore, you must run the jexegen tool from a directory above the directory containing the class files.
For example, consider the following scenario. A Java application consists of two class files, Main.class and Helper.class. The classes contained within these files have been built so that they exist in a package called Sample and the files are placed within the directory c:\classes\Sample as follows:
c:\classes\Sample\Main.class c:\classes\Sample\Helper.class
If the command jexegen /main:Main *.class is run from the c:\classes\sample directory, the generated executable will not work correctly because the names of the class files contained within the executable will not reflect their real names. The proper way to build the .exe is to run jexegen /main:Sample.Main Sample/*.class from the c:\classes directory.
You can use the /V option to observe the names of class files that are stored in the executable.
By default, the current directory is used as the base directory. Package names are determined relative to the base directory. You can use the /BASE option to specify an alternative base directory.
As an alternative to specifying all the class files and options on the jexegen command line, you can use a command file. A command file contains a list of options and/or file specifications, one per line. For example, this command line:
jexegen /main:Foo /out:Foo.exe Foo.class Bar.class Bar2.class Bar3.class
can be replaced with the following command line:
jexegen @foo.dat
where the contents of the file foo.dat is:
/main:Foo /out:Foo.exe Foo.class Bar.class Bar2.class Bar3.class
The jexegen tool works by binding the class files to a small stub program. This stub simply instantiates the VM, and uses the IJavaExecute2::SetClassSource method to tell the VM that it should look inside the executable for class files.
If the built-in stub is insufficient for your needs, you can provide your own stub file. For example, a custom stub could contain version information or a custom icon. You can use the /BINDTO option of the jexegen tool to add the class resource data to your own stub program; alternatively, you can use the /RAW option and reference the resulting data file from your program's resource script.
The SDK includes the source code for a sample jexegen stub.