Issue with 'Source not found' - java

I'm trying to debug a tomcat server. Also I have installed JadClipse in Eclipse. And I need to stop in classes which have no source file.
So. When I do 'ctrl+open implementation' on method - everything works fine(I see decompiled sources of this file). I even can put a breakpoint inside this method.
But when workflow reaches this breakpoint, it stops on it and I can't see decompiled sources.
What should I do?
And when I turn off console with launched tomcat - decompiled code comes back at the same moment.

I am a debugging adict an understand what your problem is.
It is easy to open and decompile classes that you navigate but it is difficult to do it while debugging it.
What you can try (it is a little tedious but works) it is doing a manual work. As you can see in below image, the Debug panel has different threads for you application. In this case you have a Thread with a Main class and main method, at this line you will find the line number for the process you are debugging. For example:
Main.main(String[]) line: 9
This debugging "line: 9" points you at what line in the class you are watching.
In your case, you can be guided using the line number and can use Ctrl+Open to navigate the sources. You won't see the debugging highlight since you are doing a manual work but it is really helpful to debug decompiled classes.
Hope to help.

Related

Running a java program in VScode

I start coding java with VScode recently. I have a simple problem. The problem is that I do not want the output to be like that. In other words, I do not want the program to run in the terminal as shown below. I just want the statements to be printed alone. Here, I just want (Hello world) only to be printed with nothing else. I googled how to run a java program and I found that the output must appear in either OUTPUT or DEBUG CONSOLE.
Can anyone please help me?. NOTE: I installed java 14 as well as all needed extensions in VScode for java.
If your code needn't input data, you can add this in the launch.json:
"console": "internalConsole"
The default value is:
"console": "integratedTerminal"
I do not suggest install the 'Code-Runner' extension, because it will compile the java file under the same folder of the java file, and mix them up.
And I recommended you to get used to the outputs, the outputs can provide useful information, let you know what's exactly the vscode does. If you run into some problems, you will need this information to help you to solve the problem.
In this case, you can just press Command F5 (Mac) or other keybindings (https://code.visualstudio.com/docs/getstarted/keybindings). This runs the program in your IDE. Otherwise, you can create a launch.json file to configure your debugging.
What you want to do is follow the instruction in Run and Debug Java in VS Code to setup a launch.json file. This defines how your code is launched and where the output from that debug session goes. You can customize the Debug output that appears by adding and configuring the User Settings for the Microsoft Java Debugger
Here are some things which you can do:
If you have installed all necessary extension packs, then the editor would display an option to Run & Debug the class on the code itself. (rare cases but it appeared while working in Linux)
Else type javac <name.java> in the terminal(output will be displayed in Terminal tab)
Or install the code runner extension which is available in VS Code Marketplace (that would display results in output tab easily)

Eclipse Debugger not following the source code

I have encountered a problem with the Eclipse and I am unsure how to fix it. When I enter the debugger and press the step over button the debugger usually highlights the line of source code that I stepped to. However, for some reason this is not working for me anymore. I enter the debugger and go to the breakpoint but if I hit the step button the source is not highlighted and if I continue to hit the step button I can see that the Debugger is stepping into other files (looking at the Thread) but my view of my code doesn't change. The only way I can find what line my Debugger is on is if I control click on the line from Debug tab and click Lookup Source which then highlights the line the Debug Current Construction pointer is on. If I am debugging I would like to follow this Current Construction pointer line by line. I must have accidentally altered this somehow and I am unsure how to change it back.
Simply stated the problem is this, usually the Eclipse Debugger highlights your source code as you step through it. It is not doing that for me anymore, the debugger is stepping properly but it is not highlighting the line of code that it is on.
This happens when we make Java code change in file, compiler creates a class but running server has a old copy of your class file.
Go with JRebel to get rid of such kind of issues.
This can also happen if you have more than one project in you work space, and you create a debug configuration that points at the wrong project base directory.
To resolve this:
Open your debug configuration list (Run -> Debug Configurations)
Select the proper configuration under your Remote Java Application list
Verify that you have the correct project source listed under the Base directory on the Main tab.
If you have the wrong directory selected (say, one that holds a different project), the debugger will start with no issues, but you will not be able to step through your code.
I had the same issue.
There was a workaround for that by right-clicking on associated callstack line in Debug view and selecting "Lookup Source". After that the current instruction line is (green) highlighted as usual. But I needed to do this after every debug step.
Rebuild all projects didn't help.
The solution:
Restart Eclipse and all works fine.

Java Debugging: Source not found

I am having a problem with Eclipse where I can run my program just fine, but when I try to start the debugger, I get this message
The picture is a little hard to make out, but instead of getting the normal debugging window, instead it says it is throwing a ClassNotFoundException, and is trying to dislay the source for Launcher$ExtClassLoader.
The thing that really baffles me though is that I can run the code just fine, it is only when I click the debug button that I have the problem.
I have also tried debugging at the command line with JDB, and I got the same error.
So far, I have tried Reinstalling Eclipse and downloading (what I believe to be) the correct Java Development tools for Mac OS X.
I have no idea what else I can try, so any help would be greatly appreciated. Let me know if there is any other information I can provide.
Source not found might be legitimate for dynamically loaded code (e.g. Maven).
There are three workarounds known to me (after months of search):
Connect to a running JVM with the debugger and you will see the code.
Use Dynamic Source Lookup plugin for Eclipse from here:
https://github.com/ifedorenko/com.ifedorenko.m2e.sourcelookup
Use run-jetty-run Maven plugin
http://code.google.com/p/run-jetty-run/
I prefer and recommend 3. It works and starts webapp much faster than jetty:run.
Unfortunately 2. 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
Do you have the sources for the files that you are using. If you are using Maven (M2Eclipse) you could download the sources. This might solve the problem.
Otherwise you could go and manually attach your sources. Here is how you manually attach sources.
Next you have to attach the sources-
Hope this helps
The "source not found" is a red herring - there may simply be no way to get access to the source that is throwing the error, because it is deep in the guts of the debugger's class loader.
The better question, then, is, "Why is scottrice.ChessPuzzles.ChessPuzzleDriver not being found?" The only possibility that occurs to me at the moment is that something might be weird in your debug configuration. Did you debug the program by just right-clicking a file with a main() and choosing "Debug As" -> "Java Application"?

Eclipse java debugger consistently 6 lines off of where it should be, in one file

I'm having a strange problem when debugging some java code with eclipse (Version: Helios Service Release 2 - Build id: 20110218-0911)
It works fine most of the time, but whenever I step into code in one of the files, the debugger highlights the line which occurs 6 lines behind where I currently 'am' (which I determined from looking at the stack trace). Then when I go deeper into the call tree into yet file, it starts working correctly again. I'm sure that the program I'm debugging and the file eclipse is using are in sync, and I've tried refreshing the project, restarting eclipse, and even removing and re-adding the project, with no luck.
any suggestions?
This happens quite frequently when working against class-only JAR files where a source attachment has been made - and the attached source doesn't exactly match the class byte-code. The debugger is working against the line # details included in the classes, but it won't necessarily match the attached source.

Is it possible to add breakpoints to a class which I don't have the source code for?

I want to add a breakpoint in a class in Eclipse, but I don't have the source code for it. Is it possible to add a breakpoint in it anyway? In my case I really only need to know when a method is called.
(As a side note: does anyone have the source code for j2ee_api_1_3.jar?)
If you open the outline view, you can select a method, right-click and select Toggle Method Breakpoint, this will then break whenever the method is hit.
You may be able to get the sources from Sun's archive download page
As mentioned by Rich, the outline view (available even without sources):
alt text http://help.eclipse.org/ganymede/topic/org.eclipse.platform.doc.user/images/ref-8.png
allows you to set method breakpoint, that is, provided javac compiled those classes with debug informations, including "Source Code information" (that is the case with J2EE1.4, not sure about J2EE1.3)
The source code of J2EE 1.3 should be available and be included with the download center j2sdkee-1_3_1-win.exe file.
Download jad decompiler /configure its path in eclipse through windows->preferences and open the source of the class where you need to place the breakpoint - and then debug can run as it does normally and you can see all the variable information in the variable view.
It depends, I think, on whether the class was compiled with debug information. If so, then the class file contains meta-data such as line numbers and parameter names which the debugger needs to make a decent fist of it. If not, then the debugger has less information to go on.
JavaEE libraries are notorious for not having debug meta-data compiled into them. It can be quite frustrating.

Categories

Resources