I have a Java application that must be launched from a shell script. This application uses a jar library that I want to modify and debug from eclipse. I have tried it and I failed.
What I have tried
I have compile my library to generate the jar. In the folder where the application looks for the mentioned jar, I have renamed the original one and created a symbolik link to mine.
Then, from eclipse, I have done the following:
Right click on my jar's project > debug as > debug configurations.
Select Remote java Application and Connection Type = Standard (Socket listen)
At this point, I can see a label at the bottom right telling: "Waiting to vm to connect".
Next I have gone to the application's main folder and executed the launcher script.
I am sure that the application is using the modified library because I have added a System.out.printlin("...") and I can see it in the console. Despite of this, the debug mode is not activated in eclipse, and the application is not paused.
Note: I have compiled the proyect with make.
For remote debugging, the JVM that is being used to run the application must be configured to run in debug mode. So you'll need to include those options in the script that's launching your application.
Having said that, what is so special about the shell script that it can't be converted into a run configuration to launch directly from Eclipse?
Related
I am using vscode to debug a relatively huge java application with multiple maven modules. The core application is loaded and compiled, can be launched successfully in debug mode, and all breakpoints for the code in the main thread are working properly. I managed to debug using launch and attach features.
This Java application has a feature it allows loading the Jython script which will call Java code and classes referenced in JAR files that are specified in the classpath of the java.exe command line. When the main application is launched, you can then load the Jython script. The moment you load a Jython script, it will launch that script in another thread and starts executing.
I managed to launch the application in debug mode using this command line:
>c:\path\to\jdk1.8.0_351\java.exe -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005
-Xbootclasspath/p:../lib/somelib1.jar;../lib/somelib2.jar;
-classpath .;../lib/somelib3.jar;../lib/somelib4.jar;../lib/custome1.lib;
../lib/custome2.lib
-Xincgc -Xms64m -Xmx1024m -Djava.security.policy="policy.all"
-Dpython.home=".." -Dsun.security.ssl.allowUnsafeRenegotiation="true"
-Dcom.ibm.mq.cfg.useIBMCipherMappings="false"
com.main.AppFrameClass
The above command line is a summarized version of the one I am using to clarify the problem.
From VS Code, I managed to attach it to the running application using this setting in vscode launch.json:
{
"type": "java",
"name": "Attach to java debug port 5005",
"projectName": "Some_Project_Name",
"request": "attach",
"hostName": "localhost",
"port": "5005",
"sourcePaths": [
"path/to/source/code/src/main/java"
]
}
The good thing is that if I set a breakpoint on the core application in the main thread, the execution will stop, and I can see the source code and debug without any problem.
In another separate small maven project (which is supposed to be part of the core application), I developed customization for some of the classes in the main application. The custom code is compiled and generated custom JAR files which are added to the classpath of the command line java.exe used to launch the main application. I simply copy the JAR files with the customization to the lib folder of the main application and launch the application using the correct command line which is similar to the one I mentioned above.
The main application and the customizations made are working fine.
My issue is that the breakpoints set for the Java code called from Jython are not working in vscode. In other words, the Jython code is invoking java code which is part of the customized code, and breakpoints set in that code are not working.
Following are the steps I followed to debug and set breakpoints:
Open the main Maven project in vscode.
Open the other Maven project (2nd project) with the customizations using the vscode file/add a folder to the workspace.
Wait until extensions are activated, builds are completed, and both projects are recognized.
Now, I can see the projects under the "JAVA PROJECTS" section as well as under the "MAVEN" section on the left side. No errors and all seem fine.
Save the workspace to a .code-workspace file.
Launch the application with the customization using the command line similar to the one mentioned above - java.exe ..... The launching will happen from another folder on the same laptop using a clean install of the main application with the customized JAR files. It will not launch the application using the Maven Projects of VScode.
From vscode debug view, run the attach debug configuration. It is successful.
Now, the main application is loaded successfully, and all breakpoints in the main thread are hit successfully in vscode.
Set a breakpoint in the Java code which is related to the customized parts in the 2nd Maven Project. Note that the main Maven Project and the Customization Maven Project are two separate projects in the vscode workspace, and they are not connected or related together. I am thinking that this is fine but not sure.
From the main application, load the Jython script that will invoke Java code/classes in the customized JAR files.
Now, here is the problem. I see that the debugger in VSCode is triggered, but I don't see the source code popping up as usual. I see that the debug controls are active, and when I try to click "Next Step" for example, I see the error: Failed to step because the thread 'thread-name' is not suspended in the target VM.
I repeated the steps above several times, but sometimes I don't see the error above when I step through the code. The execution will break and pause, and I can see the debug statements output is correct (in the application output), but, I don't see the source code of the related breakpoint, and I cannot watch any variable.
I appreciate your help to solve this problem.
See the snapshot below for more details.
I could not solve the problem in vscode, but, in less than 5 minutes, I achieved what I wanted to do in Eclipse.
The problem in vscode is that the debugger is breaking somewhere between Jython and Java. I see this error on the "CALL STACK" section on the left panel:
Illegal character <<> at index 71: C:/path/to/project/main/java/source/folder\org\python\pycode\<string>
See the snapshots below for details.
I thought if I kept only one project open in vscode and connect to the remote application running in debug mode, I thought it would work. No matter what I do, it won't show the source code while stepping through the debugging session. In vscode, if I set a breakpoint in the source code, it will break correctly, and I can step through, but the source code is not shown. I cannot even see the binary JAR anywhere on the screen which would allow me to attach the source in vscode. Usually, I see a decompiled version of the class, and I can right-click and attach the source from a ZIP or JAR file, but, in this case, I could not find this option while in the debug session.
Then, I switched to Eclipse and disconnected the debugging session from vscode. In Eclipse, I opened the same project and set up Remote Debugging, and it worked right away without any effort. I think vscode is a waste of time if you want to go to the next level with Java Projects.
I have seen many online tutorial explaining how to use eclipse to do remote debug of WAR file.
But what I want to know is how to do the debug inside eclipse just as debugging a JAVA application? I have Tomcat 7 configured in my eclipse as a server. And I have tested it with a sample servlet program successfully meaning I can set breakpoint in the source code and run into it.
My WAR application is built by gradle. I have imported the gradle project into my eclipse and build it ok inside eclipse by running gradle task inside "gradle tasks view". I added the project into the server. However, when I try to use "Debug as > Debug on Server", it fails and the breakpoint is not get hit. Anyone could share the experience to debug WAR inside eclipse?
I am a IntelliJ Idea user but I have a generic advice here. What you can do is that you can run your application (war/jar etc) with debug port on and then from eclipse use remote debug (or attached to a process sort of option).
Make sure you have exact copy of the code from which you have created war/jar otherwise lines might mismatch while debugging and will be hard to make sense.
On the "Servers" view, select the right tomcat server overview, then go on the "Modules" tab.
There, you can add the war by clicking on "Add External Web Module...".
Set the war path in the "Document base", and what ever you want on the "Path" field.
Example:
Document base: "C:\eclipse-workspace\MyProject\war\myWarToDebug.war"
Path: "/myapp"
Start the server in debug mode. Access your app using the url
<yourServerHost>:<serverPort>/<pathSetInModuleTab>.
Note that when reaching the breakpoint, Eclipse may say there is no sources found. Simply go on the server debug configuration and add the project sources in the "Source" tab.
Before debug you must decompile using jd gui for open class file inside war file and save as java project.
I'm developing a datastore plugin to Geoserver, to develop it faster I am trying to remote debug it. Geoserver uses Tomcat behind the curtains. I prepared everything to remote debug via Eclipse and accomplished it. Now I can remote debug my plugin. However, when I modify my code (I tried to add a harmless line like: int noHarm = 5;) and then export it as jar and copy that jar to webapps\lib\ under Geoserver installation directory, I fail to remote debug the plugin. After that I changed that modification back to when it was worked(deleted int noHarm = 5;) and created the jar again, then copied it under webapps\lib\ , now I am able to remote debug again.
When I open stores page in Geoserver, it stops at breakpoints in the canProcess() method with the jar exported from not modified code or when I try to add new Store it stops at breakpoints in the createDataStore() method with the jar exported from not modified code. But if I change even a tiny line or add it won't stop at breakpoints even though it connects to virtual host succesfully(I use vmware workstation with windows 7-32 bit on it if it helps).
What could be the problem?
Thanks very much in advance.
I found the solution, it was about eclipse. My source files was not in the workspace so, in the project build path --> under the source tab I was using Link Source button. That button allows you to link java files (which are not under your workspace) to your project and let those files act as source. What I did to solve this problem:
I then moved those files under project's real source folder
With that I created jar.
I stopped Geoserver(Tomcat) and copied my jar under webapps\lib\
I started Geoserver(Tomcat) and connected to server via eclipse remote debug.
After these steps I was able to remote debug with every jar I deployed.
I need to debug a Java application I have no source code for. It is running locally on a Jetty server. Decompiling using JD-GUI works fine. Attaching JDB via a socket connection or shared memory works fine, too.
Where I fail is joining the pieces together. I mainly tried Eclipse with the JD-Eclipse plugin and remote debugging. I failed to find a way to successfully attach the debugger to a running process. Everything seems to assume that I have at least parts of the application available as source code in a project, but I have not. And it is quite a large application (200+ MiB of JAR files and 500+ MiB of other stuff) so trying to build a project from all the decompiled classes and getting this to run is not an option unless it is easy to automate.
What I really need is being able to attach a debugger to a running process, see and navigate the decompiled code, set breakpoints and inspect variables and objects. It does not matter if the code could be recompiled. Conditional breakpoints and expression evaluation would be nice to have.
You can probably do this with the help of a combination of jd-eclipse and its extension jd-eclipse realignment fragment.
JD-Eclipse
Realignment fragment
The process for installing this is quite simple:
Install JD-Eclipse following the steps provided in the
JD-Eclipse site (the process is quite simple)
Restart Eclipse
Download Realignment realignment.jd.ide.eclipse_1.0.2.jar
Copy the file to the \dropins
Restart Eclipse
Go to Windows -> Preferences
Navigate to General -> Editors -> File Associations
Select *.class in the File types section, select Realignment for JD
Class File Editor in the Associated editors section and click the
Default button.
Press OK and start debugging!
here is a possible solution:
run the jar with arguments below:
java -agentlib:jdwp=transport=dt_shmem,address=XXXXX,server=y,suspend=n -jar YourJar
run jdb in eclipse using Run->External Tools to connect to the running jvm
jdb -attach XXXXX
set breakpoints using jdb cmd like:
stop at <TheClassName>:<ThePosition>
I will try it when I'm free, will update if it works
updates:
I've figured it out today:
unzip jar file
jdb -sourcepath [unzipped jar path] -classpath [your main class path]
after jdb initializing, excute:
stop at <package>.<yourclass>:<linenunmber>
run <your main class, for example org.springframework.boot.loader.JarLauncher>
after breakpoint triggered, you can step by step debug using jdb command
I added a Java project to Eclipse and I am running it from the command line. Since it was pre-built, I did not build it. The project, OfBiz, is enabled for remote debugging. Do I need to compile the project in Eclipse before I can remote debug into it?
No you don't need to recompile, but you have to start your application with options like:
-Xdebug -Xrunjdwp:transport= dt_socket,address=1044,server=y,suspend=n
The port here 1044 of course can be changed.
If you application is running, open the debug dialog and attach the eclipse debugger to the application's JVM using "Remote Java Application" / New
EDIT: I forgot to mention that this requires that the precompiled app is start externaly. If you wan't to start it from inside eclipse, you would have to recompile otherwise eclipse can not find the 'Main' class to execute.