Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attach the Source in Eclipse of a jar

I added a Student.jar into my Build Path in my eclipse like this-

Right click on the project->BuildPath->Configure Build Path->Libraries->Add External Jars

There is one class named StudentTest in Student.jar file. When I was debugging my code in eclipse, I stepped into that StudentTest class in the Student.jar.

And after that eclipse shows me like this-

The JAR file S:\some_location\Student.jar has no source attachment. You can attach the source by clicking Attach Source below

Now I am not sure how should I attach the source in my eclipse. And from where? Can anyone provide me step by step what I need to do.

Update:- I tried unzipping the Student.jar and I got Student folder. And after that I tried pointing the source to Student folder But still I am not able to see the class properly so that I can debug it properly, it shows the same above behavior.

like image 583
AKIWEB Avatar asked Mar 02 '13 22:03

AKIWEB


3 Answers

Use Java Source Attacher !

It does what eclipse should do - a right click context menu that says "Attach Java Source.

enter image description here

It automatically downloads the source for you and attaches it. I've only hit a couple libraries it doesn't know about and when that happens it lets you contribute the url back to the community so no one else will have a problem with that library.

like image 197
oikonomopo Avatar answered Oct 17 '22 13:10

oikonomopo


Eclipse is showing no source found because there is no source available . Your jar only has the compiled classes.

You need to import the project from jar and add the Project as dependency .

Other option is to go to the

Go to Properties (for the Project) -> Java Build Path -> Libraries , select your jar file and click on the source , there will be option to attach the source and Javadocs.

like image 27
Avinash Singh Avatar answered Oct 17 '22 13:10

Avinash Singh


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.

like image 16
meriton Avatar answered Oct 17 '22 15:10

meriton