Eclipse java debugging: source not found

后端 未结 30 1636
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:23

    I had this problem while working on java code to do process on a excel file containing a data set, then convert it to .csv file, i tried answers to this post, but they did not work. the problem was the jar files themselves. after downloading needed jar files one by one(older releases) and add them to my project, "source not found" error vanished. maybe you can check your jar files. hope this would help.

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

    Eclipse debugging works with the class actually loaded by the program.

    The symptoms you describe sounds like the class in question was not found in the project, but in a distribution jar without debug info found before the project you are working with.

    This can happen for several reasons but have a look at the location where the classes showing this behaviour is found (look in the navigation pane to identify it). You will most likely need to change the build path of the project to avoid using this jar and have the JVM use the project instead.

    EDIT: Note that as of 2018 it is common to use a build framework like Maven, where the build path is managed by the m2e plugin so this problem should be very less frequent than when the question was asked. If you use Maven and m2e, make sure to enable Preferences / Maven / "Download Artifact Sources" or right-click the project, Maven / "Download Sources".

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

    Well, here's what worked for me. I tried every possible solution on StackOverflow that there was. I tried changing my source location in the debug menu, I installed the m2e Eclipse plugin, I changed from embedded Maven, and I installed the run-jetty-run and nothing worked. Now, I will caveat that I was not trying to view an external person's source code, I just wanted to see my OWN code, but every time I "stepped in" to my methods that I wrote that were in MY project, I got the "Source now found" error.

    After finally asking an expert, my issue was that the first thing Eclipse was doing was calling a ClassLoader, which you can see from the debug stack. All I had to do was F6 (step over) and then it took me back to my original call and then F5 (step in). And there was my code. Sigh...such a simple fix but an hour wasted.

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

    For beginners,

    There is a possibility that the jar file is a part of the project which you have not yet included in the Eclipse workspace.

    For that, you need to know the project name of the jar file. Say for example, its abc-18.0.0-SNAPSHOT.jar, it means that the project you are supposed to include in your workspace is abc.

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

    Go to Debug configuration in eclipse and use below goal to run your application.

    -Dmaven.surefire.debug

    e.g

    -Dmaven.surefire.debug exec:java

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

    In my case with tomcat projects I have checked project here: Window - Preferences - Tomcat - Source Path - Add java projects to source path

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