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
![]() |
. . . 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 build-bin.javac: Copying 1 file to /home/amit/temp-workspace/openjdk/openjdk/j2se/dist/bin shared.build: build: 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 'HelloWorld.java'
amit@ubuntu-laptop:~/temp-workspace/openjdk/openjdk/j2se/dist/bin$ ./javac HelloWorld.java
If the file is compiled successfully you can then execute it using your JVM installation.
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)
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!
1.http://nb-openjdk.netbeans.org/get-and-build-compiler.html
2. http://openjdk.java.net/groups/compiler/
--By Amit Kumar Saha
| project.png | ![]() |
36969 bytes |