How to tell which jar a given class comes from?

Sorry for a very-simple-looking question, but I don't know how to do it in Idea.

8 comments
Comment actions Permalink

Alt+F1 followed by Enter will take you to the location of the currently open
class in the project view. Is that what you're after?

Sorry for a very-simple-looking question, but I don't know how to do
it in Idea.



0
Comment actions Permalink

Sorry for my English. Your answer implies that my english is so bad that my question was not understood at all. Let me paraphrase it.

I use a lot of jar files as libraries in my project (for example, lib1.jar, lib2.jar ....). I know that the class com.somecompany.Something is from one of the jar files. I want to know exactly which jar file contains that class.
Thank you.

0
Comment actions Permalink

Chris' answer is still valid. Use Alt-F1, 1 to navigate to the class in the
project view, then have a look at the parent nodes. You will find the specific
jar file there.

Thai Dang Vu wrote:

Sorry for my English. Your answer implies that my english is so bad that my question was not understood at all. Let me paraphrase it.

I use a lot of jar files as libraries in my project (for example, lib1.jar, lib2.jar ....). I know that the class com.somecompany.Something is from one of the jar files. I want to know exactly which jar file contains that class.
Thank you.

---
Original message URL: http://www.jetbrains.net/devnet/message/5242140#5242140

0
Comment actions Permalink

This is not "in Idea" but here is a script that will answer the same question:

#!/bin/bash

# nasty script to find a string in the contents of a jar file.

# probably a better way to do this, but then again...


if [ "$1foo" = "foo" ] ; then

echo "$0 usage: `basename $0` string"

echo "where string is the string to look for in the jar's contents"

exit 1

fi


for i in `find . -name \*.jar`

do className=`(jar tvf $i | grep $1)`;

if [ "$className" != "" ]; then

   echo -e "$i\t$className";

fi

done


(not originated by me)

save as "whichjar" or "whichjar.sh", make it executable, put it in your path, then go to a parent directory containing the jars and type:

whichjar com.full.package.ClassName

and it will tell you which jars contain that class.


0
Comment actions Permalink

i just want to add a little to other guys

1) ctrl+n, mark checkbox 'Include non-project classess), start typing name of class, when it appears in dropdown list select it with arrow keys, then press ALT+F1 and you will see your class in project view

2) if you are on source code, you can ctrl+click (or ctrl+b) on your class to open it, after it opened you can look at IDEA window title it will contain whole path to your class including .jar file
but if have javadocs or sources for it you will there path to docs, not to class
then first method will work -> ALT+F1 when inside editor

0
Comment actions Permalink

To add a little more to the discussion and provide another alternative way of finding this out...

If you are in source code, put your cursor on the class name or variable you want to know about. Hit Ctrl+Q to bring up the quick documentation. In the top right corner of the documentation window will be the name of the library the class is from. It will be the name of the library as you named it when you added it to your project dependencies in IDEA. Or something like"Maven:org.apache.common.common-lang-1.0" if you are using Maven and maven auto imported the library as a dependency.

This way of doing it will tell you the name of the library definition it is from. So if I add the jar "log4j,jar" to my project as a library named "The Log4J Library", it will show the name "The Log4J Library", not "log4j.jar". But if you typically name your libraries the same as the jar names (or something very close) that is not an issue. If you have multiple jar files added to a library definition, it will not tell you which of jars in that library definition the class is from. But in most cases just knowing which library it is from is enough. If not, one of the ways the above posts mention will work to determine the exact jar.

I hope that helps.

1
Comment actions Permalink

1. Place the cursor over the class and press CTRL, You will get Class name definition along with jar from which it was extracted.

2. Ctrl+Click on Class name it will open the class byte code then place ur cursor over Class name on the tab. You will get the jar name and package name in which class resides.

0
Comment actions Permalink

1- Double click on our class name (eg: import org.slf4j.Logger)  eg , docuble click on "Logger" class

2. Press "Ctrl+n" , then you see which package it belongs , to which maven dependency it belongs , to which jar file it belongs . 

 

This owkred ona  community edition , hope thsi helps . 

 

 

 

)

0

Please sign in to leave a comment.