4

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?

durron597
32.5k18 gold badges106 silver badges164 bronze badges
asked Nov 7, 2011 at 20:56

3 Answers 3

6

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

answered Nov 7, 2011 at 21:37
Sign up to request clarification or add additional context in comments.

2 Comments

Yes, this filters out the *.java files, I can't even expand the packages.
OK, did some testing, this is still possible with caveats. Sounds like it won't help in your case though. Answer updated.
5

Extract the jar in some source directory (it's a zip file), and create a project with this directory as source.

Or, if this source jar file contains the sources of a classes jar file that is used as a library in your Eclipse project, just right-click on this jar file, select "Properties", then "Java Source Attachment", then "External File", and select the source jar file. Then each time you browse a class from this classes jar file, Eclipse will automatically show you its source code.

answered Nov 7, 2011 at 21:05

Comments

0

If you want just to open jar o war files (and search or browse scripting code), install the Eclipse plugin called "Eclipse zip editor", from eclipse marketplace. Just in case it's the website to drag and drop to eclipse

enter image description here

answered Dec 15, 2017 at 2:22

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.