I am doing remote debugging of a Java application and using the debug view of Eclipse. The basic debugging process is working fine and I can see the method stack traces in debug view at the relevant breakpoints. However, I am not seeing the corresponding source code in the tab below and it is saying:
Source not found
The source files are already in my Eclipse project and I can see them in the Java view. I have edited the source look up paths and added the *.java files to it. But even then I am not seeing the source code in the debug view where the execution halts. Any clues on this would be appreciated.
For the Run/Debug configuration that you have been using to Remote Debug, have you followed these steps :
“Run -> Debug configurations…”
Choose the remote config from the tree on the left
Click on the “Source” tab
Click on the “Add…” button
Follow the wizard (add the Project containing the source which is being debugged).
If so, can you post a snapshot of the Run Configuration ?
What I have usually done with a Remote Debug run configuration is Add Source as Java Projects to the Source tab on the Run/Debug configuration. Thus to add a project called so, I would proceed as follows :
And when choosing the project, select the two checkboxes :
To end up with this finally :
I have done the below steps and it worked for me:
Run > Run Configurations
Java Application > Click on Source Tab
Include the project by selecting the option "File System Directory"
Debugging started showing the source code.
You are probably using JRebel which is automatically recompiling and reloading classes. Unfortunately Eclipse Debugger doesn't work with class realoaded in this way. In order to make sure that Eclipse will work fine with the class after changes you have to restart your web application container.
Related
I have installed Eclipse 2020-12 (4.18.0). And also imported 2 Gradle Java projects.
When I try to debug it, so for that I need to provide Debug configuration as we do in Eclipse.
I clicked on Debug Configuration-> Remote Java Application -> New Configuration->Connect.
But while doing that, there are no projects shown when I click on Browse Button.
How to solve this problem?
Also , when I open any java file , it shows 'J' symbol as shown below. J's outlining is double.
Actually, the project was not able to build itself. And Build Path was not shown under Project Properties. So just go to Project > Properties > Project Facets and tick Java from there.
That's all.
Have you tried to open Package explorer(the thing that shows all the files)?
If not go to
window--> show view --> Package explorer
I'm currently experiencing a problem with 'hot code replace' not working on Eclipse Galileo and JBoss 4.2.3.
Among other applications I'm running an exploded Java WAR on my local JBoss. The project from which it is build is managed by Maven. I build the project using the Maven goal war:exploded and then I copy that directory to JBoss with an ANT script.
When I'm now running the application and set a breakpoint anywhere in the code, Eclipse properly halts at that line in the debug mode.
But when I'm making a change to the source file and save it, Eclipse doesn't apply this change to the JBoss.
For example, when I make a normal code line into a comment, the debugger still steps over this comment as if it was regular Java code. Or when I remove a line, the debugger seems to get out of sync with the file and starts stepping over parenthesis.
But I'm not getting any 'hot code replace error'-messages either. It seems to me that Eclipse applies the changes to the source files, but doesn't apply it to the JBoss.
Are there any special preferences that have to be turned on in order to make hot code replace work? Or are there any mistakes in how I build and deploy the application to the JBoss?
I did not work with JBoss but I have two suggestions.
If you run your application in eclipse using the launch configuration
Is your "Project" - "Build Automatically" flag enabled?
If not, the code is not compiled and ignored t runtime.
When you debug an application in remote mode, you can not change the code, but you can change the value of parameters. (I think)
I had issues in a project with Maven and Eclipse. No errors were shown, but hot code replacement was not working. I read that "Build Automatically" has to be checked. I checked this and it still didnt work. I had some errors in other projects in my build path. I believe that was the error. When i researched, I found that the we had to uncheck the "Abort build when buildpath errors". I have given the details in the link below.
I had a similar problem with Open Liberty. Let me build on the accepted answer plus the answer from #user513365 (since a link there is now dead).
In my case I had two issues:
1. Build path errors
In my case my Incomplete build path was because I was using a Maven project with only src/main/java but without a src/test/java (so probably could have solved this by creating the latter).
But I was able to fix Hot Code Replace by going to Preferences -> Java -> Compiler -> Building and make one of two changes:
Either:
uncheck Abort build when build path errors occur OR
using the drop-down, change Incomplete build path from Error to Warning.
2. Make sure Eclipse-built classes are getting loaded
In my case my remote JVM was using a full JAR artifact from my local .m2 Maven repository. The accepted answer of enabling: "Project" - "Build Automatically" misses a subtlety here.
The Eclipse project build in my case is only going to do a hot code replace, if I do the Eclipse build after the debugger is attached. Yes, it will do the Eclipse build automatically, but if I restart my remote JVM and simply attach the debugger, it is still configured to load this class from my local .m2 JAR, and NOT pick up my local change.
FINAL NOTE ON THIS ANSWER VS. OTHER ANSWERS
If you are constantly changing the class that you are building automatically you might not notice the subtlety in point 2., and the accepted answer combined with the build path error mentioned in #user513365's answer will be all you need.
First check is the Project/Build automatically.
It may be also required to check the application server deployment configuration,
E.g. for JBoss, in Eclipse, in the Servers view, double click on the server and there is a Deployment Scanners section with two check boxes:
Add missing deployment scanners
Remove added deployment scanners before shutdown
https://docs.jboss.org/author/display/AS7/Deployment+Scanner+configuration
JBoss AS/ Deployment Scanner configuration
I just recently had this problem in Eclipse 2019-06 and found I had to uncheck the option in "Replace classfiles containing compilation errors" in Preferences->Java->Debug->Hot Code Replace group. All the other options there were checked.
Previous to doing that I was getting "Hot code replace failed - Delete method not implemented" despite my only change being to ass a System.out.println call.
As soon as I changed that option ( in the same debug session ) it started working for me.
Looking into Eclipse 4 RCP.
Did the following:
Created an Eclipse Plugin Project (no Rich Client unchecked,
Actvator unchecked) so no classes under /src
Created a Product Configuration. Application selected is
E4Application
Created a Feature Project and include the plugin I created in step
1
In the .product file I checked the configuration to be based on
features. In the dependencies tab I added org.eclipse.e4.rcp and
the feature I created in step 3 (added required dependencies as
well)
Created Application Model with container to be the plugin project
of step 1 and added a New Trimmed Window
Saved all and tried to launch an Eclipse Application
No window is showing up and I don't see an error in console.
Any idea what am I missing here or how is this debugged?
Update:
I am following: 10. Tutorial: From Plug-in to Eclipse 4 application
The 10.6. Start application is the one that fails
Update 2:
I noticed that some directories have been created outside of my workspace with the name runtime-todo.product (i.e. the plugin name).
Going into runtime-todo.product\.metadata\.plugins\org.eclipse.e4.workbench and deleting the workbench the window showed up.
Why are these directories created outside my workspace and what was the problem here?
I followed all your steps and got the expected empty window after the application started, so something is strange here.
You can try to:
Look for an error log file in the .metadata folder of your runtime workspace
Delete the file .metadata\.plugins\org.eclipse.e4.workbench\workbench.xmi
Add -clean as a program argument to your product launch configuration
Try to start the application again.
If this doesn't help, you can set a break point at org.eclipse.e4.ui.internal.workbench.swt.E4Application.loadApplicationModel to see what happens when Eclipse tries to load your application model (see also Eclipse 4 Source). I hope this helps!
[Update]:
When you start your application, a runtime workspace is created. Here, all the meta data of your application is stored, like settings and resources. For example, in .metadata\.plugins\org.eclipse.e4.workbench\workbench.xmi the user settings of the Application Model are stored.
Sometimes during development, this workspace can become corrupted (e.g. by stopping the application while debugging before settings are saved etc.).
You can see the location of your runtime workspace when you look into the Run Configuration of your application. In the Main tab you can see (and change) the workspace data location. You should keep this runtime workspace separate from your development workspace.
[Update 2]:
Information about the role of the workbench.xmi file can be found here: Constructing the runtime application model. The web page of Lars Vogel offers a lot of useful Eclipse Tutorials at Eclipse Plugin and Eclipse RCP Tutorials.
The Eclipse Help page lets you browse the user and developer guides or search for specific topics. Information about the Eclipse launcher and thus the runtime can be found here in Plug-in Development Environment Guide > Reference > Launchers > Eclipse Application Launcher. Look under Main Tab for explanations about workspace data.
The Eclipse variables are explained in the run configuration dialog of your application. In the main tab, look for the Variables... button. When you select a variable, an explanation is given in the Variable Description field.
You can check the Clear flag in your run configuration or specify -clearPersistedState in your product definition ... as mentioned here in a Lars Vogel Tutorial (search for Problem "Application model changes are not reflected in the Eclipse 4 application" in Table2).
When I'm debugging my code in Eclipse, I get annoyed when I open up the editor to find out I cant edit it because I'm actually viewing the source of the .class file. How do I get Eclipse to open up the .java file instead of the .class file when in debug mode?
EDIT: When I hit a breakpoint in my code, it brings me to MyFile.class, instead of MyFile.java, so I can see my code but not edit it.
EDIT: I'm guessing it has somethign to do with Android and ADT R18
After I finally found some time and good reason to look into this issue a bit deeper I'll elaborate a bit on Thornbjorn's answer.
As of lately, Google changed the way your Android projects package your external Android libraries. In ADT R17 (I think) it started packaging the external projects source into .jar files and including them directly into your project in the Android Dependencies or /libs folder.
Now, when the debugger hits a breakpoint, it brings up your source code in the .jar, essentially telling you to edit a .class file. The problem is that this file is read-only and so you have to go find your .java source manually. (Pain)
The fix is to right click the Project name in the debug view, and select "Edit Source Lookup..." from the menu. From there, remove the Default lookup path. After that, manually add the associated projects (not jars) that your project references. This is done by clicking Add, selecting Java Project, then checking the appropriate projects.
OK, so I hate to be "that guy", given the number of people for whom this worked, but this didn't work at all for me. I mean that the "Edit Source Lookup..." menu item was not in the context menu. I did not miss the instruction to do this in the Debug Perspective (presumably in the Project Explorer in the Debug Perspective). I tried it while the app was running and while the app was suspended. I tried checking the menu for the application's project (presumably what the instructions refer to) and for the library's project. No dice. This is with the latest Eclipse build.
However, I was able to resolve the issue:
Set a breakpoint in either your application or the library you are trying to link source for. You can actually put this anywhere as long as the library you are trying to link source for has a function that will appear on the call stack when the breakpoint is hit.
Start debugging your application.
Navigate your app to hit the breakpoint.
Make sure you are in the Debug perspective.
In the Debug tab (where the call-stack appears), find any function from your library.
Right-click that function. The "Edit Source Lookup..." menu option should be there (close to the bottom).
From here, the instructions are the same as Styler's. Click "Add", select "Java Project" and add your project (or multiple projects).
Before you exit the "Edit Source Lookup..." window, if you are like me, you will see that Eclipse has chosen to add a bunch of stuff to the list that you didn't choose. Some of that stuff (probably under expandable items with names like "Android Private Libraries" may be the jars for the libraries you just added source for. Remove those jars from the list.
Profit!
Open main project properties -> Java Build Path -> Projects tab and add there projects the main project depend on.
Switch to Order and Export tab and uncheck Android Dependencies
Enjoy
For some reason Eclipse does not believe that the class file comes from your Java file. This is frequently a malconfigured buildpath, or a jar-file used instead of the project generating the jar file.
Look in the project manager panel (<->button) to see where Eclipse finds the class file and then figure out why it uses that location instead of your project with the source file.
I'm currently experiencing a problem with 'hot code replace' not working on Eclipse Galileo and JBoss 4.2.3.
Among other applications I'm running an exploded Java WAR on my local JBoss. The project from which it is build is managed by Maven. I build the project using the Maven goal war:exploded and then I copy that directory to JBoss with an ANT script.
When I'm now running the application and set a breakpoint anywhere in the code, Eclipse properly halts at that line in the debug mode.
But when I'm making a change to the source file and save it, Eclipse doesn't apply this change to the JBoss.
For example, when I make a normal code line into a comment, the debugger still steps over this comment as if it was regular Java code. Or when I remove a line, the debugger seems to get out of sync with the file and starts stepping over parenthesis.
But I'm not getting any 'hot code replace error'-messages either. It seems to me that Eclipse applies the changes to the source files, but doesn't apply it to the JBoss.
Are there any special preferences that have to be turned on in order to make hot code replace work? Or are there any mistakes in how I build and deploy the application to the JBoss?
I did not work with JBoss but I have two suggestions.
If you run your application in eclipse using the launch configuration
Is your "Project" - "Build Automatically" flag enabled?
If not, the code is not compiled and ignored t runtime.
When you debug an application in remote mode, you can not change the code, but you can change the value of parameters. (I think)
I had issues in a project with Maven and Eclipse. No errors were shown, but hot code replacement was not working. I read that "Build Automatically" has to be checked. I checked this and it still didnt work. I had some errors in other projects in my build path. I believe that was the error. When i researched, I found that the we had to uncheck the "Abort build when buildpath errors". I have given the details in the link below.
I had a similar problem with Open Liberty. Let me build on the accepted answer plus the answer from #user513365 (since a link there is now dead).
In my case I had two issues:
1. Build path errors
In my case my Incomplete build path was because I was using a Maven project with only src/main/java but without a src/test/java (so probably could have solved this by creating the latter).
But I was able to fix Hot Code Replace by going to Preferences -> Java -> Compiler -> Building and make one of two changes:
Either:
uncheck Abort build when build path errors occur OR
using the drop-down, change Incomplete build path from Error to Warning.
2. Make sure Eclipse-built classes are getting loaded
In my case my remote JVM was using a full JAR artifact from my local .m2 Maven repository. The accepted answer of enabling: "Project" - "Build Automatically" misses a subtlety here.
The Eclipse project build in my case is only going to do a hot code replace, if I do the Eclipse build after the debugger is attached. Yes, it will do the Eclipse build automatically, but if I restart my remote JVM and simply attach the debugger, it is still configured to load this class from my local .m2 JAR, and NOT pick up my local change.
FINAL NOTE ON THIS ANSWER VS. OTHER ANSWERS
If you are constantly changing the class that you are building automatically you might not notice the subtlety in point 2., and the accepted answer combined with the build path error mentioned in #user513365's answer will be all you need.
First check is the Project/Build automatically.
It may be also required to check the application server deployment configuration,
E.g. for JBoss, in Eclipse, in the Servers view, double click on the server and there is a Deployment Scanners section with two check boxes:
Add missing deployment scanners
Remove added deployment scanners before shutdown
https://docs.jboss.org/author/display/AS7/Deployment+Scanner+configuration
JBoss AS/ Deployment Scanner configuration
I just recently had this problem in Eclipse 2019-06 and found I had to uncheck the option in "Replace classfiles containing compilation errors" in Preferences->Java->Debug->Hot Code Replace group. All the other options there were checked.
Previous to doing that I was getting "Hot code replace failed - Delete method not implemented" despite my only change being to ass a System.out.println call.
As soon as I changed that option ( in the same debug session ) it started working for me.