This post originated from an RSS feed registered with Java Buzz
by dion.
Original Post: Maven javap Plugin
Feed Title: techno.blog(Dion)
Feed URL: http://feeds.feedburner.com/dion
Feed Description: blogging about life the universe and everything tech
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>