Eclipse java debugging: source not found

后端 未结 30 1634
Happy的楠姐
Happy的楠姐 2020-11-22 15:43

While debugging a java app in eclipse I receive a \"Source not found\" error in two cases:

  • Stepping in to a file in a different project which
相关标签:
30条回答
  • 2020-11-22 16:20

    The symptoms perfectly describes the case when the found class doesn't have associated (or assigned) source.

    • You can associate the sources for JDK classes in Preferences > Java > Installed JRE. If JRE (not JDK) is detected as default JRE to be used, then your JDK classes won't have attached sources. Note that, not all of the JDK classes have provided sources, some of them are distributed in binary form only.
    • Classes from project's build path, added manually requires that you manually attach the associated source. The source can reside in a zip or jar file, in the workspace or in the filesystem. Eclipse will scan the zip, so your sources doesn't have to be in the root of the archive file, for example.
    • Classes, from dependencies coming from another plugins (maven, PDE, etc.). In this case, it is up to the plugin how the source will be provided.
      • PDE will require that each plugin have corresponding XXX.source bundle, which contains the source of the plugin. More information can be found here and here.
      • m2eclipse can fetch sources and javadocs for Maven dependencies if they are available. This feature should be enabled m2eclipse preferences (the option was named something like "Download source and javadocs".
      • For other plugins, you'll need to consult their documentation
    • Classes, which are loaded from your project are automatically matched with the sources from the project.

    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.

    0 讨论(0)
  • 2020-11-22 16:20

    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

    0 讨论(0)
  • 2020-11-22 16:21

    Remove the existing Debug Configuration and create a new one. That should resolve the problem.

    0 讨论(0)
  • 2020-11-22 16:22

    If you want to attach source code to any JAR by auto-downloading, try using this Eclipse plugin Java Source Attacher

    enter image description here

    0 讨论(0)
  • 2020-11-22 16:22

    If your are trying to debug your maven java project, and eclipse is not able to find your source, try one of these.

    1. Try adding these lines in the pom.xml
    <build>**<sourceDirectory>src/main/java</sourceDirectory>**...
    

    Try maven->update and then debug

    1. Go to the root directory of the project;

    mvn eclipse:eclipse

    now try debugging

    0 讨论(0)
  • 2020-11-22 16:23

    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

    0 讨论(0)
提交回复
热议问题