1

I've downloaded an example code that has some imports, e.g:

import com.sun.net.httpserver.HttpExchange;

I have the relevant jars in my build-path, and no warning appears. But how do I know from which jars exactly I import the above? (I want to know this so I can add javadocs to those jars).

I use Eclipse IDE

squeezy
  • 607
  • 1
  • 7
  • 15
  • have a look at mvn repository http://mvnrepository.com/artifact/com.sun.net.httpserver/http/20070405 – Scary Wombat Jun 09 '14 at 07:47
  • [FindJar](http://www.findjar.com) can be helpful at times. – Rahul Jun 09 '14 at 07:48
  • What is the IDE? Most IDEs will have way to take you the class by just double clicking. That also shows which jar it came from – Jayan Jun 09 '14 at 07:48
  • Duplicate of http://stackoverflow.com/questions/19733027/what-is-the-name-of-the-jar-that-contains-my-import – Pino Jun 09 '14 at 08:18
  • In general `com.sun` classes are internal to the JDK. And one should avoid using them. It certainly might not be available in other JREs, like from the OpenJDK on Linux or MacOSX. Here it is a borrowed interface probably for http server design. – Joop Eggen Jun 09 '14 at 08:29
  • Take a look here, you can do it with Java. http://stackoverflow.com/questions/1983839/determine-which-jar-file-a-class-is-from – danieln Jun 10 '14 at 13:22

2 Answers2

3

If you are using Eclipse IDE or IBM RAD, WSAD etc, Press Ctrl+Shift+T in eclipse window. Now type the name of the class file. It will show the contained jar.

For eg: HttpExchange is present in rt.jar

enter image description here

Dinal
  • 661
  • 4
  • 9
  • 1
    I don't see the jar, just the packages, e.g: com.sun.net.httpserver - [jdk1.7.0_60] – squeezy Jun 09 '14 at 07:58
  • 1
    @fatsokol That "jdk" line means it's part of the standard JVM libraries (as does the com.sun namespace, whose classes you should almost never use explicitly, since they're not an official part of the platform). – chrylis -cautiouslyoptimistic- Jun 09 '14 at 08:04
  • @fatsokol Have added a screenshot. Open the class file in eclipse. Enable "Link with editor" button. So here you can see AWTUtilities is present in rt.jar. Similarly you can find others as well. – Dinal Jun 09 '14 at 08:14
0

in linux you can use shell-script to view inside all jar files. something like this may help you:

for i in $(ls *.jar)
do
  unzip -l $i | sed -r "s/^[ 0-9:\-]+/$i /" | grep ".class" | tr '/' '.'
done

the output is a pair of (jar-name, class-fullname) for example:

Struts-Layout-1.2.jar fr.improve.struts.taglib.layout.util.NewsCollection.class
Struts-Layout-1.2.jar fr.improve.struts.taglib.layout.util.NoColumnCollection.class
Struts-Layout-1.2.jar fr.improve.struts.taglib.layout.util.NoHeaderCollection.class
Struts-Layout-1.2.jar fr.improve.struts.taglib.layout.util.PanelInterface.class
Struts-Layout-1.2.jar fr.improve.struts.taglib.layout.util.ParentFinder.class
Struts-Layout-1.2.jar fr.improve.struts.taglib.layout.util.SelectionHelper.class
Struts-Layout-1.2.jar fr.improve.struts.taglib.layout.util.TabsInterface.class
Struts-Layout-1.2.jar fr.improve.struts.taglib.layout.util.TabsUtil.class
Struts-Layout-1.2.jar fr.improve.struts.taglib.layout.util.TagUtils.class
Struts-Layout-1.2.jar fr.improve.struts.taglib.layout.util.TreeviewInterface.class
Struts-Layout-1.2.jar fr.improve.struts.taglib.layout.util.WidgetUtils.class
Struts-Layout-1.2.jar fr.improve.struts.taglib.layout.workflow.LayoutPlugin.class
Struts-Layout-1.2.jar fr.improve.struts.taglib.layout.workflow.LayoutRequestProcessor.class
Struts-Layout-1.2.jar fr.improve.struts.taglib.layout.WriteTag.class

you can search your class in this output to find jar-file name.

Farvardin
  • 5,336
  • 5
  • 33
  • 54