Working with 'javac' shipped with Open JDK

This short tip is basically to show you how you can very easily compile the 'javac' source code bundled with Open JDK 7 using NetBeans 6- Milestone builds or Beta 1

  • Download Open JDK 7 from here
  • Open the 'javac' NetBeans project in NetBeans


  • Build it like a regular NetBeans project
14 warnings
Copying 7 files to /home/amit/temp-workspace/openjdk/openjdk/j2se/build/linux-i586/classes
Building jar: /home/amit/temp-workspace/openjdk/openjdk/j2se/dist/lib/javac.jar
Copying 1 file to /home/amit/temp-workspace/openjdk/openjdk/j2se/dist/bin
BUILD SUCCESSFUL (total time: 15 seconds)

Once you built the javac source code with NetBeans, a shell script 'javac' is produced in the directory 'installation-directory/j2se/dist/bin'. Test the 'javac' file by compiling a simple ''

amit@ubuntu-laptop:~/temp-workspace/openjdk/openjdk/j2se/dist/bin$ ./javac 

If the file is compiled successfully you can then execute it using your JVM installation.

  • However, the compilation process fails when you have got the primary JDK installed at a 'non-standard' location and have not set the PATH variable appropriately.In this case you will get errors like:
Exception in thread "main" java.lang.ClassFormatError: (unrecognized class file version)
 at java.lang.VMClassLoader
at java.lang.ClassLoader.defineClass(
at gnu.gcj.runtime.SystemClassLoader.findClass(
at java.lang.ClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(

By default the shell script has the last lines as:

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

The shell script assumes that the 'java' executable bundled with your existing 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.

ofcourse, you could also modify the PATH variable!

  • Resources



--By Amit Kumar Saha

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo