Java启动配置jvm,设置要用于小程序启动的默认JVM参数

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.

解决方案

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值