'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.
Solution 1:[1]
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.
Solution 2:[2]
Use Java Source Attacher !
It does what eclipse should do - a right click context menu that says "Attach Java Source.
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.
Solution 3:[3]
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.
Solution 4:[4]
This worked for me for Eclipse-Luna:
- Right Click on the *.jar in the Referenced Libraries folder under your project, then click on Properties
- Use the Java Source Attachment page to point to the Workspace location or the External location to the source code of that jar.
Solution 5:[5]
Go back in to where you added the jar. I believe its the libraries tab, I don't have Eclipse open but that sounds right. to the left of the jar file you added there should be an arrow pointing right, click that and 3 or 4 options expand, one of them being the source file of the library. Click on that and click edit(I think you can also double click it) then locate the file or folder on your hard disk, you probably have to click apply or okay and you're good to go, same with javadoc and i think the last one is native libraries. I don't pay much attention when I'm in there anymore if you couldn't tell. That's what you were asking, right?
Solution 6:[6]
I Know it is pretty late but it will be helpful for the other user, as we can do Job using three ways... as below
1)1. Atttach your source code using
i.e, Right click on the project then properties --> Java build path--> attach your source in the source tab or you can remove jar file and attach the source in the libraries tab
2. Using eclipse source Analyzer
In the eclipse market you can download the plugin java source analyzer which is used to attach the open source jar file's source code. we can achieve it after installing the plugin, by right click on the open source jar and select the attach source option.
3. Using Jadclipse in eclipse you can do it
last not the least, you can achieve the decompile your code using this plugin. it is similar way you can download the plugin from the eclipse market place and install in your eclipse.
in jadclipse view you can see your .class file to decomplile source format note here you cannot see the comment and hidden things
I think in your scenario you can use the option one and option three, I prefer option three only if i want to the source code not for the debug the code. else i ll code the option 1, as i have the source already available with.
Solution 7:[7]
Simply import the package of the required source class in your code from jar.
You can find jar's sub packages in
Eclipse -- YourProject --> Referenced libraries --> yourJars --> Packages --> Clases
Like-- I was troubling with the mysql connector jar
issue
"the source attachment does not contain the source"
by giving the path of source folder it display this statement
The source attachment does not contain the source for the file StatementImpl.class
Then I just import the package of mysql connector jar
which contain the required class:
import com.mysql.jdbc.*;
Then program is working fine.
Solution 8:[8]
I faced the same issue and solved using the below steps. Go to Windows->preferences->Editors->File Associations
Here click on Add then type .class click on OK
again click on Add then type .classwithoughtsource click on OK
Now you will be able to see JadClipse option under Java section in Windows->Preferences
Please provide the path of jad.exe file as shown below.
Path for Decompiler-C:\Users\ahr\Documents\eclipse-jee-galileo-SR2-win32\jad.exe Directory for temporary Files-C:\Users\ahr.net.sf.jadclipse
click on Apply
Now you should be able to see the classfiles in proper format.
Solution 9:[9]
- Download JDEclipse from http://java-decompiler.github.io/
- Follow the installation steps
- If you still didn't find the source, right click on the jar file and select "Attach Library Source" option from the project folder, as you can see below.
Solution 10:[10]
I am using project is not Spring or spring boot based application. I have multiple subprojects and they are nested one within another. The answers shown here supports on first level of subproject. If I added another sub project for source code attachement, it is not allowing me saying folder already exists error.
Looks like eclipse is out dated IDE. I am using the latest version of Eclipse version 2015-2019. It is killing all my time.
My intension is run the application in debug mode navigate through the sub projects which are added as external dependencies (non modifiable).
Solution 11:[11]
I have faced same problem and resolved it by using following scenario.
First we have to determine which jar file's source code we want along with version number. For Example "Spring Core" » "4.0.6.RELEASE"
open https://mvnrepository.com/ and search file with name "Spring Core" » "4.0.6.RELEASE".
Now Maven repository will show the the details of that jar file.
In that details there is one option "View All" just click on that.
Then we will navigate to URL "https://repo1.maven.org/maven2/org/springframework/spring-core/4.0.6.RELEASE/".
there so many options so select and download "spring-core-4.0.6.RELEASE-sources.jar" in our our system and attach same jar file as a source attachment in eclipse.
Solution 12:[12]
Try removing the breakpoints. :)
Solution 13:[13]
It is quite possible, just go to the jar in the Build Path and choose to attach a source just like follow.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow