bash command to know .jar of searched class
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
hi,
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:
find . -name "*jar" -exec jar -tf '{}' \; | grep ClassToSearchFor
is it possible to place a echo output of jar-filename in the above find command also?
thanks!
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:
find . -name "*jar" -exec jar -tf '{}' \; | grep ClassToSearchFor
is it possible to place a echo output of jar-filename in the above find command also?
thanks!
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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,...:
Regards, Andrew
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,...:
Regards, Andrew
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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).
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
Author
Posts: 836
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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!).
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Since jars are zipped, and zgrep is a combination of zip and grep, you may use zgrep:
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I use jarFinder, and find it indispensable.
| Listen. That's my theme music. That's how I know I'm a super hero. That, and this tiny ad told me: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |








