Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tools for finding all dependencies in Java jars

Are there any tools that can be given a classpath or folder, and will search through all the .jar files looking for references to a particular class?

It would have saved me a day of searching in order to resolve this kind of problem.

In my case I had to find out where a rogue reference to a class was coming from, as it was stopping JBoss from starting correctly due to a NoClassDefFoundError. I suppose I am looking for this:

java -jar magicbullet.jar /path/to/search com.myproject.DodgyClass
Searching...
com.problematic.Otherclass in /path/to/search/dodgy.jar implements com.myproject.DodgyClass

Or similar. If not, I'll write one.

like image 828
Rich Avatar asked May 19 '11 11:05

Rich


People also ask

How do I find the dependencies of a JAR file?

jar file. Use the -verbose:class option to find class-level dependencies or use the -v or -verbose option to include dependencies from the same JAR file. Use the -R or -recursive option to analyze the transitive dependencies of the com.

Does a JAR file contain all dependencies?

the executable jar should NOT contain the dependencies, just enough of your own code to run, with the dependent classes coming from the before mentioned classpath set up in the manifest.

What is jar tool in Java?

DESCRIPTION. The jar tool combines multiple files into a single JAR archive file. jar is a general-purpose archiving and compression tool, based on ZIP and the ZLIB compression format. However, jar was designed mainly to facilitate the packaging of java applets or applications into a single archive.


2 Answers

Use Tattletale - http://www.jboss.org/tattletale. It helps you create an index which is very handy to search for classes etc.

like image 149
sinha Avatar answered Oct 03 '22 10:10

sinha


Under Linux (or Cygwin on Windows) you may use script from https://gist.github.com/980697.

Usage: findclass.sh <directory> <className>

Example: findclass.sh . ClassName (means "search for class named ClassName inside all jars/wars/ears/sars located within current directory and all its subdirectories")

like image 45
Stanley Shyiko Avatar answered Oct 03 '22 08:10

Stanley Shyiko