How can I remote debug my rcp application? - java

Because my RCP eclipse application fails when run outside of eclipse, but works correctly when running inside of eclipse, I am attempting to use eclipse to remotely debug my application as it's running outside of the eclipse environment.
I am using 32 bit Eclipse 3.6.1 on a 64 bit Windows 7 machine. I am using 32 bit Java 1.6 update 37. I use the Eclipse Product export wizard to package the app, and I end up with an eclipse.exe. I have created a Remote Debug Configuration and set it to use port 8765 (random number). For debugging purposes, I start the app from the command line using this line:
eclipse.exe -Xdebug -Xrunjdwp:transport=dt_socket,address=127.0.0.1:8765
Depending on whether I am attaching or listening via my Eclipse debugger, I will add the server=[y/n] option to this command line but it seems not to make any difference.
For the configuration Connection Type I have tried both Standard (Socket Listen) and Standard (Socket Attach). When I try Socket Listen, my debugger will start listening - "Waiting for vm to connect at port 8765", but when I start my app through the command line, the app starts fine but the debugger never attaches.
When I try Socket Attach, I start the app first using the command line, then when I attempt to attach using eclipse, I get the message "Failed to connect to remote VM. Connection refused"
I've tried all the various combinations of address: localhost, 127.0.0.1, and my local IP address. I get the same result each time.
Thanks for any help!

You are missing the -vmargs parameter. Try "eclipse.exe -vmargs -Xdebug -Xrunjdwp:transport=dt_socket,address=127.0.0.1:8765"
I was searching for the same thing and found the answer in this helpful post http://blog.ankursharma.org/2010/05/remote-debugging-eclipse.html

this is better:
http://exploreeclipse.blogspot.com/2016/05/eclipse-rcp-remote-debugging.html
Defining the server and suspend arguments
$./TOS_BD-macosx-cocoa -vmargs -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8989

Another way of debugging your RCP application is to launch it with "-console" "-consolelog". This gives you the osgi console, where you can examine which bundles did (not) start, the services that are exported etc. Type help to get a list of commands available.

Related

Remote debug jnlp with IntelliJ

I am trying to debug a jnlp with IntelliJ but it keeps telling me
Unable to open debugger port (localhost:5005): java.net.connectException "Connection refused: connect"
First I start the jnlp via command line with
javaws -J-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 http://server:port/app.jnlp
afterwards I run the remote debug configuration in IntelliJ and I get the aforementioned exception
Screenshot of the IntelliJ configuration and the command line:
I've already read following questions:
Debugging JNLP started application
How can I debug applications under Java Web Start (JNLP)?
remote debugging a jnlp application with IntelliJ
Remote debugging java web start under JVM 1.8
but their answers (add arguments via Java control panel, set JAVA_TOOL_OPTIONS variable, ...) don't seem to work for me.
Any idea what I might be doing wrong?
I'm using IntelliJ 2017.1.5 and JDK1.8.0_121 on Windows 7.

Intellij IDEA remotely debug java console program

I have a remote server with Java running to which i have SSH access.
I am writing an app on the local machine, building it with maven.
Is it possible to set the IDE Itellij IDEA to run my project remotely? The idea is : to build the jar, copy it to the server, and debug the process ( or something like that).
It would be nice of you to share the settings i need to setup.
This is what I usually do to debug my remote app.
Run the server on debug mode
This can be adding this particular line when you run your application server
-Xdebug -Xrunjdwp:transport=dt_socket,server=n,suspend=n,address=9999
for JDK above 1.4, you can use this
-agentlib:jdwp=transport=dt_socket,server=n,suspend=n,address=9999
After that, run your application server
SSH Tunneling
I'm not 100% sure that you can access to your application's port directly if you're using ssh connection (well, maybe there is a way ;) ). So, first we need to expose the port for debugging that we set on first step by running this command.
ssh -f user#personal-server.com -L 9999:personal-server.com:9999 -N
Setting up the IDE
You can follow the step that #SSJVegito has said, which basically, is to point the debugger to the port 9999. Open the debug configuration in your Idea, then Change the circled value to 9999. Then, happy debugging :D
I think it's possible, I was able to do such a thing with a local server I was using to deploy my application. And since you have access to the server, it should work for you as well.
What you need to do in IntelliJ is create a Remote configuration. To do that, open IntelliJ and next to the run button (on the left), you should have your configurations, designated by a down arrow. Click that arrow and click Edit Configurations. A new window should open. Click the + sign in the upper left corner and the select Remote. A new window should appear. We now need to set the host and the port which the server uses for debugging (if you are using tomcat, it is usually 8000; in tomcat, you can locate it by opening the catalina.bat file with a text editor and looking for the JPDA_ADDRESS property, which allows you to change the port). Give your configuration a name and press Apply.
Afterwards, you need to run your configuration in Debug mode. You need to select it from the configuration list and press the Debug button located to the right of the Run button.
More details here:
http://blog.trifork.com/2014/07/14/how-to-remotely-debug-application-running-on-tomcat-from-within-intellij-idea/comment-page-1/
http://eclipse.org/jetty/documentation/current/debugging-with-intellij.html
http://www.javaranch.com/journal/200408/DebuggingServer-sideCode.html
I hope this helps.

Java plugin does not attach to debug session in Eclipse

this functionality used to work and now it seems broken, I a do not know how to diagnose it.
I am developing a java Applet that runs in a browser. I used to set up the runtime parameters in the java console to (Windows platform):
-Djava.compiler=NONE -Xnoagent -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=n,suspend=n
This setting appears both in the User and System tabs in the Java console.
Then I would start a debug session in eclipse for my applet project and set it to listen on port 8000. When I launch the browser and the applet is loaded, it would attach to eclipse and I was able to debug and set breakpoints, etc.
Now, it seems that this is no longer happening. When I launch the debug session in Eclipse, I do see port in LISTENING mode and owned by javaw.exe, which is correct. The only problem is that when the browser loads the Java plugin, it does not honor the "Runtime Parameters" and does not connect to the listening debug session in eclipse.
I have the latest Java update installed.
What else should I be looking into?
I just resolved my issue.
I edited:
C:\users\\AppData\LocalLow\Sun\Java\Deployment\deployment.properties
and added the pararameters as follows:
deployment.javaws.jre.0.args=-Djava.compiler\=NONE -Xnoagent -Xdebug -Xrunjdwp\:transport\=dt_socket,address\=8000,server\=n,suspend\=n
When i added the runtime parameters through the UI, they went to
"deployment.javaws.jre.1.args" so I duplicated them into "deployment.javaws.jre.0.args"

Attach debugger to application using Eclipse

Can you attach to a running application using Eclipse, similar to how you attach using Visual Studio?
Yes.
If you start your server with the debug port open, by adding this into your java command:
-Xdebug -Xrunjdwp:transport=dt_socket,address=127.0.0.1:8888,server=y,suspend=n
And you have the source code in your project (technically this isn't required, but it's kind of useless unless you do), you can connect to the running server by setting up a "debug configuration"
with host = the machine the server is running on and port = 8888 (for example - see options above)
You can then set break points and the debug session will halt the server there and you can inspect variables/fields, and even set their values.
Update
The more modern command-line options for the JVM to do this are
-agentlib:jdwp=transport=dt_socket,address=127.0.0.1:8888,server=y,suspend=n
The Debug Configurations panel has a menu item Remote Java Application:
How about just do this:
"Open the DDMS perspective, select the device and attach to your app's process (you will see the package name listed)"
.. thanks to this post: https://stackoverflow.com/a/10074263/2162226

What is the default properties that eclipse uses to launch a java process in its debugging mode?

I would like to connect to java process started by eclipse using a command line debugger but not sure what default properties of the eclipse launched java process are ? I wouldn't mind using attaching using sockets but not sure how much slower that would be ?
how about
-Xdebug -Xnoagent -agentlib:jdwp=transport=dt_socket,suspend=n,address=localhost:12345
then you can attach a java debugger to port 12345
I investigated on the differences of Java application startup in Eclipse between "Run" and "Debug". I used Sysinternals' Process Explorer to see the command line of the java process that Eclipse forks when starting a Java application with either option. (I'm on a Windows 7 system)
With "Run HelloWorld"
"C:\Program Files (x86)\Java\jdk1.7.0_07\jre\bin\javaw.exe" -Dfile.encoding=Cp1252 -classpath C:\workspace-juno\HelloWorld\bin com.example.HelloWorld
.......
With "Debug HelloWorld"
"C:\Program Files (x86)\Java\jdk1.7.0_07\jre\bin\javaw.exe" -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:2404 -Dfile.encoding=Cp1252 -classpath C:\workspace-juno\HelloWorld\bin com.example.HelloWorld
(The address port changed in succeeding invocations, e.g. it became address=localhost:2564 at the next invocation.)
So java (or javaw) actually gets started with different options depending on whether "Run" or "Debug" was used: the "Debug" start-up adds an additional agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:NNNN option. This is a standard way of putting a JVM into debuggable mode. The HelloWorld program will first wait for its debugger to successfully connect to it before continuing (option suspend=y). The HelloWorld JVM will connect itself automatically to some debugger running on address localhost:NNNN (... option address=localhost:NNNN and implicit default option server=n). (... Oracle provides authoritative information on the agentlib start-up options)
Eclipse itself will act as the debugger application providing a port NNNN. The HelloWorld JVM will connect to this port, via its own port of number NNNN+1 (one can see a process's used ports with Process Explorer on that process's TCP/IP tab).

Categories