In addition of a shell script, you might also use binfmt_misc tricks.
I prefer the shell script, it is probably more portable (some Linux system might not load, or have available, the kernel module required to support binfmt_misc)
As the kernel's Documentation/java.txt explains:
2) You have to compile BINFMT_MISC either as a module or into
the kernel (CONFIG_BINFMT_MISC) and set it up properly.
If you choose to compile it as a module, you will have
to insert it manually with modprobe/insmod, as kmod
cannot easily be supported with binfmt_misc.
Read the file 'binfmt_misc.txt' in this directory to know
more about the configuration process.
3) Add the following configuration items to binfmt_misc
(you should really have read binfmt_misc.txt now):
support for Java applications:
':Java:M::\xca\xfe\xba\xbe::/usr/local/bin/javawrapper:'
support for executable Jar files:
':ExecutableJAR:E::jar::/usr/local/bin/jarwrapper:'
support for Java Applets:
':Applet:E::html::/usr/bin/appletviewer:'
or the following, if you want to be more selective:
':Applet:M::<!--applet::/usr/bin/appletviewer:'
Of course you have to fix the path names. The path/file names given in this
document match the Debian 2.1 system. (i.e. jdk installed in /usr,
custom wrappers from this document in /usr/local)
using gcj
Another possibility (which I don't recommend) would be to use gcj (the old Java compiler inside GCC).
gcj enables you to compile a Java program into a native Linux ELF binary executable. But I don't recommend it because:
- few (and less and less) people inside the GCC community are working on
gcj
- few people are using
gcj ; I only met only one occasional developer using it
- so
gcj is becoming obsolete
gcj generated code which allocates a lot does not perform very well (because it uses Boehm garbage collector which is much slower than the GC in other Java implementations). However on Java code with a low allocation rate it may run quite fast (because of the powerful optimizations of GCC done in GCC language-neutral middle-end).
- the Java language supported by
gcj is a subset of some quite old Java standard.