Is there a way to make a binary executable from Java code?
There are several stunts you could try in order to accomplish this,but they all cripple the platform independence of your Java programs.
For example, on Unix or Wintel systems, you could create a shellscript or batch file that included the relevant class files, extractedthem into a temporary directory and then invoked the Java interpreteron the class files with the right arguments. This means you caninvoke the program with just one command without having to set aCLASSPATH variable first or to explicitly invoke the Java interpreteron the commandline. In fact, this is how HotJava (itself written inJava) is invoked. But shell scripts are not very cross-platform andintroduce bugs and insecurity for the user.
If shell scripts are not an option, you could write a C program thatset the appropriate environment variables and then invoked a secondarybinary – in this case the Java interpreter – with the right set ofparameters. Unix platforms can do this with the system() call, otherplatforms also have similar system-dependent library routines thatallow applications to invoke other programs. The class files canbe statically compiled into the binary as arrays of data or canaccompany the program as set up files depending on how tightly youwish to bundle the various files.
Both of these stunts of course, assume that you have the Java interpreteravailable on the system. If that’s not the case, then you can prettymuch forget having an executable Java program because your Java applicationwill need the Java libraries, class files, and set up info thatcomprise Java’s core packages.
This may become less of an issue in the future since most computervendors have announced plans to make a Java virtual machine implementationavailable for their platforms. This would mean that every systemwill have a Java interpreter or just-in-time compiler built rightinto the operating system of the machine.