Revenge of the Ted: Yay Servlets! “We have more dogs that an online dating service”
Aug 22

Maven javap Plugin

Builds, Java Add comments

Javap is one of those utils that gets installed with Java, that some never find. Javap is helpful for poking around in bytecode found in the classpath.

One of the ways I use javap is to just find out if a certain class is in my CLASSPATH (as well as learning about the methods etc).

As soon as you are in a real build environment, you need to make sure that a class is in the CLASSPATH that your build is working on.

Since I spend time in Maven-land, I use a tiny little maven plugin which does the work to find out if a class is in the dependency list for a project:

maven -Dclass=java.lang.String javap

The bulk of the work looks kinda like this:

<goal name="javap:classpath:check" description="Check Classpath">
<fail message="Must set the 'class' variable. E.g. maven -Dclass=java.lang.String javap." unless="class"/>

<available property="class.found" classname="${class}" classpathref="maven.dependency.classpath"/>

<j:choose>
<j:when test="${class.found}">
<echo>Class Found: ${class}</echo>
</j:when>

<j:otherwise>
<echo>Class NOT Found: ${class}</echo>
</j:otherwise>
</j:choose>
</goal>

Download Maven Javap Plugin

Leave a Reply

Spam is a pain, I am sorry to have to do this to you, but can you answer the question below?

Q: Type in the word 'cricket'