Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I browse the source code in a jar file containing source code in Eclipse?

I have a jar file that contains source code. How can I browse this source code in Eclipse?

At the moment, my Eclipse opens the jar file in a Text Editor, and it isn't that helpful.

When I look in the preferences "General" > "Editors" > "File Associations" I have no associations for *.jar and if I look in the available "Editors" I can't find anyone that seem to be a good fit for jar files.

How can I browse the source code in a jar file using Eclipse? Is there any Editor I should configure for jar files?

like image 862
Jonas Avatar asked Dec 21 '22 06:12

Jonas


1 Answers

If you have the jar added to a project's classpath, you can view its source by:

  1. Expanding Referenced Libraries in the Package Explorer view
  2. Expand the jar you're looking at
  3. Double clicking on a .class file

You need both the .class and .java file in the jar to view source, though.
If you have only the .java file, the class won't appear at all.
If you have only the .class file, the class will appear as bytecode.

Example:

screenshot of eclipse with referenced jar expanded

like image 179
Chris Avatar answered Apr 08 '23 00:04

Chris