3

I am trying to remote debug a Java applet, but I cannot seem to get the -agentlib:jdwp JVM argument to work. I have tried specifying it in the Java control panel for the particular JRE used, and I have tried setting it via the JNLP file used to launch the applet.

What is the correct way to set JVM parameters for applet launch? In particular, to debug remotely.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Phoebe
  • 2,774
  • 3
  • 22
  • 27

5 Answers5

3

Looking at a similar SO question, I found the following answer...

Sometimes to debug some security related stuff the browser plugin environment is just too different from appletviewer. Here's what you can do to effectively debug applets in the browser:

1) Obtain debugging info for the binaries

Backup the .jar files from JRE_HOME/lib

(Download and) Install a JDK for the same version as your JRE.

Copy the .jar files from JDK_HOME/jre/lib to JRE_HOME/lib

The files inside the JDK were compiled with the debugging information included (source-code line number information, variable names, etc) and the JRE files don't have this information.

Without this you won't be able to meaningfully step into core class code in your debugger.

2) Enable debugging for the Java Plug-in

Go to the Java Control Panel / Java / Java Runtime Settings / View / User / Runtime Parameters

And add the options to enable debugging. Something like this:

-Djava.compiler=NONE -Xnoagent -Xdebug -Xrunjdwp:transport=dt_socket,address=2502,server=y,suspend=n

The interesting options are the port (using 2502 here, you can use pretty much any free port, just write it down for later) and the suspend - if you need to debug the applet startup, classloading, etc, set this to "y". That way when you access an applet page, the browser will appear to freeze as the JVM immediately gets suspended waiting for a debugger to connect.

3) Use your favorite IDE to Remotely debug the Java Plug-in

In Eclipse, for instance, choose Run / Debug Configurations ... / Remote Java Application

Click on the "New" button.

Make sure connection type is "Socket Attach", choose localhost as the host if your browser is local, and the port you chose earlier (2502 in the example).

You might have to inlude the src.zip in your JDK on the sources tab to have the Java core class sources available.

Save the configuration, and once your browser is running the plug-in (with the JVM suspended or not) run the remote debugger to connect to the plug-in JVM, with a project containing your applet sources open.

Community
  • 1
  • 1
11101101b
  • 7,679
  • 2
  • 42
  • 52
  • Thanks for sharing! I have been, more-or-less, trying exactly this. The console reports that it got the arguments, but the applet does not suspend, nor does it respond to a debugger connection. – Phoebe Mar 08 '13 at 22:28
  • I had an edit for the post that clarifies how to do it w/ 7, but it is moderated so it has not shown up yet. Short answer: try -Djava.compiler=NONE -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=2502 – Phoebe Mar 12 '13 at 14:11
  • I just tried that, @Zach, and it didn't seem to work for me. At least you got it to work, right? – 11101101b Mar 13 '13 at 15:11
  • 2
    Yes! I have it working. I had to set the JVM parameters by running bin/javacpl.exe (rather than the real control panel), and it did not work if suspend=n. If suspend=y, all applets halt until a debugger attaches. – Phoebe Mar 13 '13 at 18:52
  • The other funky thing is that since I am using the "new style" JNLP applet launch, I did have to connect two debuggers -- one for the applet launcher and one for the applet itself. – Phoebe Mar 13 '13 at 18:53
  • 1
    See my answer to [a similar question here on SO](http://stackoverflow.com/questions/16315892/java-7-debug-on-windows-8-not-working/16363990#16363990). This is something that just happened in the latest version of the plugin JVM. The short answer is you can set params for javaw.exe, but these never get passed onto java.exe, which is what's actually running in the browser plugin. You can verify this on Windows by inspecting the JVM process with Process Explorer. FWIW, I've filed a bug with Oracle on this issue. – Spanky Quigman May 06 '13 at 13:57
2

This issue has been fixed for 7_u40 which is available for early access on java.net. Otherwise the Oracle bug says this is fixed for Java 8!

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=8016005

http://jdk7.java.net/download.html

0

Do you absolutely need to run the applet within a browser? Because the normal way to debug applets is with the appletviewer.


According to the JPDA docs (which I'm assuming you've read, based on the things you've already tried), you should be able to specify the agent in the Java Control Panel. I've never tried this, and the doc claims that you can't interrupt the applet launch this way (just attach to a running applet), so all I can do is wish you luck.

parsifal
  • 501
  • 2
  • 4
0

I have a workaround. It seems like it's JRE7_u21 that doesn't open a port, doesn't suspend, and jconsole VM summary doesn't show the VM parameters configured in the Java control panel.

I downgraded to JRE7_u17 and everything works. My VM arguments string in the Java control panel is:

 -agentlib:jdwp=transport=dt_socket,address=8889,server=y,suspend=y,quiet=n,timeout=10000  

it seems to work without

 -Djava.compiler=NONE

Nothing else has worked, not even replacing the lib folder as previously suggested. I even tried some registry hacking (changing paths).

jsaddwater
  • 1,781
  • 2
  • 18
  • 28
0

You can use JAVA_TOOL_OPTIONS environment variable to pass the default JVM params. It will pass the params to your applet which is running in the browser (and not only to the applet). This approach will work even on java 7u21 and higher.