This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
sometimes i come across the problem that a NoClassDefFoundError occurs and I don't know the jar for it. Searching manually is cumbersome, so I want to find out by bash command.
Following gives me a list whether it could be found out by a list of jars, but it does not give me the information which jar it is:
Possibly the easiest way is to search for just the unqualified class name in the jar file itself (so don't try to give it any package names, and don't try to list the contents of the jar file). Assuming you don't have too many files to search through, you grep for the class name in the list of jar files:
If there are too many files to list on the command line in that way, you could try a much slower method such as looking at each file individually:
Of course we can then start making the commands even more complex to show exactly which class we found (in the cases where there may be multiple matches), and expand our search to include wars, ears, sars,...:
How about:where you replace CLASS_NAME with the class name? For example:would give you a list like this:so you know the VTITemplate class resides in the derby-10.2.2.0.jar file. That's quite efficient, and for small numbers of JARs quite readable too.
You could be more sophisticated with grep or sed to parse that output further if you needed to be (e.g. to only output lines ending .jar which come before a line ending .class).
Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / AmazonAmazon UK )
Charles Lyons
Author
Ranch Hand
Joined: Mar 27, 2003
Posts: 836
posted
0
Or this:which is better. I haven't tested it thoroughly, but you'll get output which is the JAR name followed by all matching names in that JAR. There are undoubtedly shorter and more efficient ways to do this---the above just came out of my head (and therefore, could be dodgy, so use carefully!).