How to Attach Source in Eclipse

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.

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.

In Eclipse, how to attach different source files when debugging

In the Debug view, select the Debug tab. Right click your debug instance and choose "Edit source lookup..."

See below:

Sample Image

Be sure to run a Project Clean after changing the source lookup. I have run into many inconsistencies in various versions of Eclipse with this feature.

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 to attach source in Eclipse project for lib with no sources JAR ?

I just tried it in my workspace and was able to resolve the source files properly. The trick is that when you select the external location, you should pick the 'external Folder' instead of 'External File'.

I selected the External Folder with path cas-server-4.0.0/cas-server-core/src and it worked.

Sample Image

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



Related Topics



Leave a reply



Submit