While debugging a java app in eclipse I receive a \"Source not found\" error in two cases:
The symptoms perfectly describes the case when the found class doesn't have associated (or assigned) source.
But what if Eclipse still suggest that you attach source, even if I correctly set my classes and their sources:
This almost always means that Eclipse is finding the class from different place than you expect. Inspect your source lookup path to see where it might get the wrong class. Update the path accordingly to your findings.
Eclipse doesn't find anything at all, when breakpoint is hit:
This happens, when you are source lookup path doesn't contain the class, which is currently loaded in the runtime. Even if the class is in the workspace, it can be invisible to the launch configuration, because Eclipse follows the source lookup path strictly and attaches only the dependencies of the project, which is currently debugged.
An exception is the debugging bundles in PDE. In this case, because the runtime is composed from multiple projects, which doesn't have to declare dependencies on one another, Eclipse will automatically find the class in the workspace, even if it is not available in the source lookup path.
I cannot see the variables when I hit a breakpoint or it just opens the source, but doesn't select the breakpoint line:
This means that in the runtime, either the JVM or the classes themselves doesn't have the necessary debug information. Each time classes are compiled, debug information can be attached. To reduce the storage space of the classes, sometimes this information is omitted, which makes debugging such code a pain. Your only chance is to try and recompile with debug enabled.
Eclipse source viewer shows different lines than those that are actually executed:
It sometimes can show that empty space is executed as well. This means that your sources doesn't match your runtime version of the classes. Even if you think that this is not possible, it is, so make sure you setup the correct sources. Or your runtime match your latest changes, depending on what are you trying to do.
You might have source code of a dependency accessible to Eclipse. But Eclipse does not know for source code for code that is dynamically loaded. E.g. through Maven.
In case of Maven, I recommend that you use run-jetty-run plugin:
http://code.google.com/p/run-jetty-run/
As a workaround you can also connect to a running JVM with the debugger and you will see the code. Alternatively you can use Dynamic Source Lookup plugin for Eclipse from here:
https://github.com/ifedorenko/com.ifedorenko.m2e.sourcelookup
Unfortunately it didn't helped me as it has issues with Windows paths with spaces.
I have filled an enhancement request on Eclipse Bugzilla and if you agree this issue "Source not found" should vanish forever, please vote for it here:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=384065
Thanks!
Sasa
Remove the existing Debug Configuration and create a new one. That should resolve the problem.
If you want to attach source code to any JAR by auto-downloading, try using this Eclipse plugin Java Source Attacher
If your are trying to debug your maven java project, and eclipse is not able to find your source, try one of these.
<build>**<sourceDirectory>src/main/java</sourceDirectory>**...
Try maven->update and then debug
mvn eclipse:eclipse
now try debugging
I've had a related issue in connection with Glassfish server debugging in Eclipse. This was brought about by loading the source code from a different repository (changing from SVN to GitHub). In the process, the wrong compiled classes were used by the Glassfish server and hence, the source and run time would be out of sync with break points appearing on empty lines.
To solve this, rename or delete the top folder of the classes directory and Glassfish will recreate the whole class directory tree including updating the class files with the correctly compiled version.
The classes directory is located in: /workspace/glassfish3122eclipsedefaultdomain/eclipseApps/< your Web Application>/WEB-INF/classes