Monday, May 13, 2013

Remote debugging Applet with Eclipse


Configure Eclipse for remote debugging an applet. The applet will be running on an internet browser. When a breakpoint is reached, Eclipse should suspend allowing the code to be debugged.

Java provides a protocol to achieve this. You can look for JDWP in Java documentation for more information. This protocol allows debugging even a simple class. It works with a server-client mechanism. Either eclipse or the browser can be set as server.


1.        First, I need to configure the server. I will use eclipse as server, and the applet will be the client.

From the eclipse menu choose the option: Remote Java Application.
I used the following values:

Connection Type: Socket Listen
       Port: 9100  - You can use any value, just make sure the port is not busy.


2.        Now, I need to configure the client. Since I am using the browser, I will set the values to the JRE the browser uses.

Go to: Control Panel -> Java -> (Go to Java Tab) -> Java Runtime Environment.

And add the following line to the Runtime Parameters:


The port must match the one you configured in eclipse and the option server must be set to 'n'.  You also need to make sure to add the parameters to the correct JRE.

* Like I said, you can debug even a single class. To debug a standalone class or jar use the line like this:
java –jar -agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=9100 <class or jar>

 3.        Add some breakpoint to your code. Run the applet from your browser and the breakpoint should be hit.


This is a very simple task. However, it does not always work as expected (what software does?) I hope this tips can help you to save some time.

1.      If it does not work try again with a different version of Java. The newest versions seem to have some security features that block the remote debugging. I was able to make it work with JRE. 1.7.0_17.

2.      Verify that your JRE is receiving the values. You can see them in the console.   

3.     For some weird reason, sometimes the values seem no to be passed. Try setting them using JRE_Instalation/bin/javacpl.exe window.

4.      Signing the JAR does not seem to be necessary.

5.      You can specify the JRE to use in the applet tag to be sure that you are using the correct JRE. Add the following line to your applet tag.
      <param name="java_version" value="1.7.0_17"/>
6.   The jar does not need to be deployed on a server in order to debug it. For this test I created an applet and put it in a jar. Then I created a simple html file with the applet tag. I open my html in a browser, and it worked fine.


No comments:

Post a Comment