Reputation: 47124
The project I'm working on has about 10 jar files as libraries. At the top of one of the files there's an import statement like:
import jpe.nar.crat.maker.ObjectMakerFactory;
Is there a way to tell which Jar file it comes from?
(I'm using Netbeans if that matters.)
Upvotes: 16
Views: 15808
Reputation: 915
In Eclipse just do Ctrl-Click on the class name (in import sentence), then Right- Click on .class code, to open a dialog,·and finally chose Declarations-project.
Upvotes: 0
Reputation: 185
In the Netbeans IDE: In your code, ctrl-select the class name. After the relevant java file comes up in the editor (if you don't have source for the class, it might not show much). Right-click anywhere in the source window and select "Select In Projects". The class will show highlighted in the jar where it came from.
This has been working at least as far back as Netbeans 8.0.
Upvotes: 3
Reputation: 1399
A former colleague of mine, Tom, wrote JarSniffer (http://sourceforge.net/projects/jarsniffer/). It's a handy little tool to find a class in a set of jars, zips and directory trees.
Upvotes: 0
Reputation: 41
Have you tried doing a 'Open Declaration' on the class? In Eclipse, when you do it, it opens a window that shows the name of the jar and tells you that this jar has 'No Source Attachment'. I am hoping something similar should happen for NetBeans.
Thanks, R
Upvotes: 4
Reputation: 9687
I like JFind very much:
... it works recursively by looking into jar's, inside war's, inside ear's, etc...
If you wrap the java launcher in a shell script and put that on your PATH, it becomes a very powerful tool:
I.e. to find all EntityManager
classes in directory jboss-6.0.0.20100429-M3
:
$ jfind.sh EntityManager ./jboss-6.0.0.20100429-M3
Search String: EntityManager
Windows Search Location: jboss-6.0.0.20100429-M3
....jjj.jjjjjjjjjjj
ClassName = javax/persistence/EntityManager.class
JarName = jboss-6.0.0.20100429-M3\client\hibernate-jpa-2.0-api.jar
----------------
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
ClassName = org/apache/xerces/impl/XMLEntityManager.class
JarName = jboss-6.0.0.20100429-M3\client\xercesImpl.jar
----------------
A little shell wrapper for use in Cygwin:
if [ $# -ne 2 ]
then
echo "Usage: `basename $0` <classname> [<fromDir>]"
exit 1
fi
echo Search String: $1
SEARCH_LOCATION=`cygpath -w $2`
echo Windows Search Location: $SEARCH_LOCATION
java -jar `cygpath -w $HOME/bin/JFind.jar` "$1" "$SEARCH_LOCATION"
echo
Upvotes: 3
Reputation: 14661
Programmaticly or interactively?
You can try DocJar. In Eclipse control click on the item will show you (the edit panel will show the source (if attached) or the methods available while Package Explorer will open the tree to the class), I would be surprised if Netbeans did not behave in a similar manor.
Upvotes: 1
Reputation: 93167
You can use the Jar Class Search for netbeans. I'm not sure that it still compatible, but it's worth the try.
Upvotes: 2
Reputation: 1108732
You can use CodeSource#getLocation()
for this. The CodeSource
is available by ProtectionDomain#getCodeSource()
. The ProtectionDomain
in turn is available by Class#getProtectionDomain()
.
URL location = ObjectMakerFactory.class.getProtectionDomain().getCodeSource().getLocation();
System.out.println(location.getPath());
// ...
Upvotes: 14