Search code examples
javaworldwind

Viewing code in a JAR file


I am a Java beginner, using Eclipse. I am trying to understand the NASA World Wind package. Specifically code that looks like this:

    protected WorldWindow wwd;
    protected StatusBar statusBar;
    protected ToolTipController toolTipController;
    protected HighlightController highlightController;

When I mouse over "WorldWindow" it says

Note: This element neither has attached source nor attached Javadoc and hence no Javadoc could be found.

The code compiles and runs, though.

However, it points to a package in a JAR file. I can find the class it is referring to. But I cannot read the class file. When I double click on it, I get "Source not found" in the Class File Editor.

I want to understand how this code works. How can I read the class files within the JAR?


Solution

  • The project you are using is open source, so you have a few options at this point.

    1. Ideally you can associate the source code and javadoc with the .jar file in Eclipse. This will allow you to directly view (read only) the source and documentation for the library from within Eclipse. To do this, you will need to:
      • download the source code and/or the javadoc. These items may very well be included in the archive you used to originally download the project (either as a jar, zip, or expanded subdirectory).
      • inform Eclipse about the relationship between your compiled jar file and the source/javadoc. See this guide
    2. ☆ instant gratification ☆ View the source code directly from the project repository. The World Wind project appears to be accessible at http://worldwind31.arc.nasa.gov/svn/trunk/WorldWind/src/
    3. You can decompile the compiled code. This solution is more useful if you're trying to investigate a closed source project or if you're debugging something unusual.