Compiling with JDK 1.5

Posted by admin
on October 11, 2006 @ 03:42 AM
Prior to JDK 1.5, javac ignored classpath manifest.mf entries in jar files, for example:

- someclass.java references classes in child.jar
- parent.jar includes child.jar in its classpath manifest

Running:
javac -classpath parent.jar someclass.java

you receive "class not found" errors for the classes included in child.jar.

I can see how in some cases this was inconvenient as it meant that if a product (such as Orbix) splits its functionality over a lot of .jar files, then you have to list most/all of these .jar files in your CLASSPATH when compiling the project.

The Java 1.5 compiler is now aware of Manifest.mf files within jar files. This introduces some unexpected side effects as the javac 1.5 looks to recursively walk/unwind the jar stack. Depending on the number of jars in the manifest, this can increase compile times considerably. If you run into this problem the quickest solution looks to be to remove the jar containing the manifest from your CLASSPATH. Other JDK tools such as javap, javadoc, etc.. still ignore the Manifest.mf file.

Thanks to Ciaran McHale for the heads up on this one.

Monitoring Memory with Jconsole and JMX in JDK 1.5 0

Posted by dave
on October 07, 2006 @ 05:14 PM
In JDK 1.4.x monitoring the JVMs memory usage was an arduous task requiring a special unsupported JVM. I'd heard JDK 1.5 had improved support but I haven't had a reason to look at it until this week. It was a nice surprise to see how easy it is to enable monitoring:

1. Add -Dcom.sun.management.jmxremote to your java command line (and start your process).
2. Start [java 1.5]\jdk\bin\jconsole. Your done.

Example:


>java -version
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode)

>java -Dcom.sun.management.jmxremote SoapDemo 

>jps
2672 SoapDemo
3784 Jps

>jconsole 2672

In this example we check the jvm version is 1.5 or greater, enable the JMX agent, and launch jconsole with the correct proccess id (2672). The console monitors the process and allows you to track memory usage in all generations of the JVM Heap, Thread State and you can also enable/disable verbose gc dynamically.

A more detailed overview of jconsole can be found here.