Thursday, October 18, 2007

visualvm: Introduction to VisualVM

visualvm: Introduction to VisualVM: "VisualVM is a tool that provides detailed information about Java applications while they are running. It provides an intuitive graphical user interface that allows you to easily see information about multiple Java applications. Java applications are run by a Java Virtual Machine, or VM. The name VisualVM comes from the fact that VisualVM provides VM information visually. As of October, 2007 VisualVM is still under development and is therefore considered an experimental tool. All feedback and suggestions are welcome! Please send your ideas to System Requirements The VisualVM tool itself must be run with JDK 6. It can display information, however, on any Java application that is running on JDK 1.4.2 or higher. The amount of information VisualVM can provide on a Java application is determined by the version of the JDK that is being used to run that Java application (more details below)"

Tuesday, October 16, 2007

Which class or resource is being lodaed?

I was having a problem with spring not being able to parse the applicationContext.xml. I finally checked and found out the wrong applicationContext.xml was first in the CLASSPATH. The code to do this is easy: System.out.println(this.getClass().getClassLoader().getResource("applicationContext.xml")); You can also find class files. To find java.lang.Object use System.out.println(this.getClass().getClassLoader().getResource("java/lang/Object.class")); The result is something like: jar:file:/C:/Program%20Files/Java/j2sdk1.4.2_14/jre/lib/rt.jar!/java/lang/Object.class Notice how the JRE version is in the output.


Retrotranslator is a Java bytecode transformer that translates Java classes compiled with JDK 5.0 into classes that can be run on JVM 1.4. Of course there is a Maven plugin. I needed to do some unit testing of some code that uses JavaMail. Poking around I found mock-javamail that does just that. However, it is written in Java 5 and I am stuck in the prehistoric world of Java 1.4. At first, I converted the code to 1.4 but that leaves 2 different code bases. Then I was pointed at retrotranslator that would give a 1.4 compatible jar from 1.5 source. One code base. Nice.

Monday, October 8, 2007

Using Maven to create a one-jar executable jar.

Oliver's Blog: "Using Maven2 to generate an executable JAR" Has instructions on getting the onejar-maven-plugin to work. This is similar to what UberJar used to to do. It takes all maven dependencies and places those jars into the output jar. It does not explode the jars as the assembly plugin is wont to do. Instead, it used the one-jar package that has a classloader that knows how to look into the jar file for other jar files. It makes for a cleaner jar file that is easier to maintain later. It does allow the filename to be specified, but does not seem to allow manifest entries, like Implementation-Version. Thanks Oliver.