Bringing military-grade cybersecurity solutions to the enterprise and critical systems.
Telephone: 310.356.7869

Finding the right JAR

Category: Java

11:59 PM, Fri, Jan 18 2008

    [javac] /home/hh/account/src/account/web/ 
  cannot find symbol
    [javac] symbol  : class JMXConfigurationMBean
    [javac] location: class account.web.ImageServlet
    [javac] (JMXConfigurationMBean)MBeanServerInvocationHandler.newProxyInstance(


That's happened to all of us, right? It used to be easy to put the right JARs onto the classpath, because there probably weren't that many packages in use. Now, an application may need a dozen or more JARs, and finding the right JAR to include from the entire JBoss tree, or the JBoss Seam tree, can be an annoyance.

I wrote up a quick utility to scan through JAR files and find the class you are looking for. It's not a full-featured application, and it isn't beautiful code, but it does what I need. It also demonstrates using the java.util.jar.JarFile class, and shows how to process an entire tree of files without using recursion. It also handles exploded JAR files correctly. JBoss has the ability to deploy JAR files which are actually directories with a name like MyApp.jar/. These exploded files (including exploded WAR and EAR files) are convenient to work with.

The FindJar utility is fast; it can search for a class in all the JARs in the JBoss distribution in a couple of seconds. Future enhancements could include searching for JARs inside unexploded WAR and EAR files. It would be easy to add a graphical JAR browser, too.

Download the FindJar compiled code and source. Using it is easy:

> java -jar FindJar.jar javax.servlet.http.HttpServletRequest
/usr/java/jboss/client/servlet-api.jar  javax.servlet.http.HttpServletRequest
/usr/java/jboss/server/default/lib/servlet-api.jar  javax.servlet.http.HttpServletRequest
/usr/java/jboss/server/all/lib/servlet-api.jar  javax.servlet.http.HttpServletRequest

In other news, we updated the Master Sauce Seam project generator. It's our alternative to Seam-Gen. Try it out!