Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Wednesday, February 10, 2016

Java - How to find out which Jar file an import comes from?

Java - How to find out which Jar file an import comes from?


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.)

Answer by BalusC for Java - How to find out which Jar file an import comes from?


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());  // ...  

Answer by Colin Hebert for Java - How to find out which Jar file an import comes from?


You can use the Jar Class Search for netbeans. I'm not sure that it still compatible, but it's worth the try.

Answer by mlk for Java - How to find out which Jar file an import comes from?


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.

Answer by Jan for Java - How to find out which Jar file an import comes from?


I like JFind very much:

http://jfind.sourceforge.net/

... 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`  []"    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  

Answer by Roy for Java - How to find out which Jar file an import comes from?


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

Answer by OliBlogger for Java - How to find out which Jar file an import comes from?


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.


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.