Attach the Source in Eclipse of a Jar

Attach the Source in Eclipse of a jar

A .jar file usually only contains the .class files, not the .java files they were compiled from. That's why eclipse is telling you it doesn't know the source code of that class.

"Attaching" the source to a JAR means telling eclipse where the source code can be found. Of course, if you don't know yourself, that feature is of little help. Of course, you could try googling for the source code (or check wherever you got the JAR file from).

That said, you don't necessarily need the source to debug.

No source attachment in Java

The .jar file is the generated packed classes of the java code. Some jars will come with java doc and code and others won't.

For recent Eclipse versions:

right-click the jar in question (in the referenced jars, not the physical jar) and choose Preferences -> Javadoc. Here give a correct location (zip/URL) to the correct javadoc. (Select Validate!)

For older Eclipse versions:

First: Navigate to the jar itself in the Eclipse project explorer (to the left) and try to open aclass of the jar. Then, you will see the warning that it has no source attachment, and a button to attach the source code.

Then, push the button, select "external folder" and then navigate to the folder with source you already have.

Attach the Java Source Code

Normally, if you have installed the JDK6u14, eclipse should detect it and declare it automatically in its "installed JRE" list.

If not, you can add that JDK through "Windows/Preferences": Java > Installed JREs:

Just point to the root directory of your JDK installation: it should include the sources of the JDK (src.zip), automatically detected and attached to rt.jar by eclipse.

Add JRE VM, from pic.dhe.ibm.com/infocenter/iadthelp/v8r0/topic/org.eclipse.jdt.doc.user/tasks/images/task-add_jre_std_vm.PNG

How to attach source or JavaDoc in eclipse for any jar file e.g. JavaFX?

You can configure the Javadocs with downloading jar, basically javadocs will be referred directly from internet.

Complete steps:

  1. Open the Build Path page of the project (right click, properties,
    Java build path).
  2. Open the Libraries tab.
  3. Expand the node of the library in question (JavaFX).
  4. Select JavaDoc location and click edit.
  5. Enter the location to the file which contains the Javadoc.
    Specifically for the javaFX javadoc enter http://docs.oracle.com/javafx/2.0/api/

for offline javadocs, you can download from : http://www.oracle.com/technetwork/java/javase/documentation/java-se-7-doc-download-435117.html

After clicking Accept License Agreement you can download javafx-2_2_0-apidocs.zip

How do I attach source code into a project's library in Eclipse?

First of all, there's nothing to be debuged at @Autowire is just an annotation. The only thing you will see there is its attributes. That's it. The interesting code is in AutowiredAnnotationBeanPostProcessor.java

Anyways, if you want to attach source zips to a jar. In Eclipse is as easy as:

  1. Your Project (Right Click) > Preference
  2. Select Java Build path (Left menu) > Libraries (Tab)
  3. Look for the jar an do click on its arrow
  4. Select source attachement

Here an example of the process.

If you are insterested on how Annotations works. I suggest this tutorial Java Tutorial - Annotations.

How can I link source to a jar package in eclipse?

I "Saved all sources" with jd-gui into my build path as ch.ntb.usb.src after unzipping the jar file. Then I set the source attachment of the external library to ch.ntb.usb.src. This fixed the issue.

Eclipse : How to remove the attached Source which was added to a Jar

Open the .classpath file and delete the source attachment part.

Or in the Build Path control panel, find the jar file and remove the source attachment (it is one of the detailed options there).



Related Topics



Leave a reply



Submit