Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Eclipse (Java), how do I determine where an import is actually coming from?

Tags:

java

eclipse

Say you're working on a Java project in Eclipse and you're looking at a import statement like:

import com.somefirm.somepackage.AClass;

and the classpath for the project has a million and one .jars on it.

How do you determine where the import is coming from?

like image 303
looeeese Avatar asked Jul 17 '09 15:07

looeeese


People also ask

How do you find out which jar file an import comes from?

You can use CodeSource#getLocation() for this. The CodeSource is available by ProtectionDomain#getCodeSource() .

How do you check where a method is called in Eclipse?

Select mymethod() and press ctrl + alt + h . To see some detailed Information about any method you can use this by selecting that particular Object or method and right click. you can see the "OpenCallHierarchy" ( Ctrl + Alt + H ).

How do I manage imports in Eclipse?

To enable this, go to Windows -> Preferences -> Java -> Editor -> Save Actions and then enable Perform the selected action on save -> Organize imports. After this, whenever you save a java file, eclipse will remove the unused imports automatically.


1 Answers

Open declaration (F3) on the import line. This will open the Java or Class file that the import resolves to.

Once that files is open, you can right-click on the declared type and choose "Show In->Package Explorer" to see where it is declared.

Alternately, if "Link with Editor" is selected in Package Explorer, the related package/jar will already be open for your inspection.

like image 165
David Citron Avatar answered Nov 05 '22 07:11

David Citron