Open JDK: ‘javac’ compilation Tip

by Amit


Here is a simple note you might find useful while compiling/building javac bundled with Open JDK 7

please note that this tip is needed only if you got the primary JDK installed at a ‘non-standard’ location and have not set the PATH variable appropriately.

Once you built the javac source code with NetBeans, a shell script ‘javac’ is produced in the directory ‘installation-directory/j2se/dist/bin’. By default the shell script has the last lines as:


mydir="`dirname $0`"
java -jar "${mydir}"/../lib/javac.jar "$@"

Now, if you try to compile your ‘java’ program using the shell script you will get errors :

Exception in thread "main" java.lang.ClassFormatError:
com.sun.tools.javac.Main (unrecognized class file version)
at java.lang.VMClassLoader
.defineClass(libgcj.so.70)
at java.lang.ClassLoader.defineClass(libgcj.so.70)
at java.security.SecureClassLoader.defineClass(libgcj.so.70)
at java.net.URLClassLoader.findClass(libgcj.so.70)
at gnu.gcj.runtime.SystemClassLoader.findClass(libgcj.so.70)
at java.lang.ClassLoader.loadClass(libgcj.so.70)
at java.lang.ClassLoader.loadClass(libgcj.so.70)
at gnu.java.lang.MainThread.run(libgcj.so.70)


This is because, the shell script assumes that the ‘java’ executable bundled with your exisiting JDK is accessible from anywhere in the path. Now, to make this work, just replace the above lines with the following, so as to point to your current JDK installation:

mydir="`dirname $0`"

/home/amit/jdk1.6.0_02/bin/java -jar "${mydir}"/../lib/javac.jar "$@"

where, “/home/amit/jdk1.6.0_02/bin/” is the path of your JDK installation.

Resources

Advertisements