设置用于小程序启动的默认 JVM 参数 [英] Set default JVM parameters to be used for applet launch

查看:27
本文介绍了设置用于小程序启动的默认 JVM 参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试远程调试 Java 小程序,但我似乎无法让 -agentlib:jdwp JVM 参数起作用.我曾尝试在 Java 控制面板中为所使用的特定 JRE 指定它,并尝试通过用于启动小程序的 JNLP 文件来设置它.

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.

为小程序启动设置JVM参数的正确方法是什么?尤其是远程调试.

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...

有时为了调试一些与安全相关的东西,浏览器插件环境与 appletviewer 差别太大.以下是在浏览器中有效调试小程序的方法:

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) 获取二进制文件的调试信息

从 JRE_HOME/lib 备份 .jar 文件

Backup the .jar files from JRE_HOME/lib

(下载并)安装与您的 JRE 版本相同的 JDK.

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

将 .jar 文件从 JDK_HOME/jre/lib 复制到 JRE_HOME/lib

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

JDK 中的文件编译时包含调试信息(源代码行号信息、变量名等),而 JRE 文件没有这些信息.

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) 启用 Java 插件调试

转到 Java 控制面板/Java/Java 运行时设置/查看/用户/运行时参数

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

有趣的选项是端口(此处使用 2502,您几乎可以使用任何空闲端口,只需将其写下来以备后用)和挂起 - 如果您需要调试小程序启动、类加载等,请将其设置为你".这样,当您访问小应用程序页面时,浏览器将看起来冻结,因为 JVM 会立即挂起,等待调试器连接.

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) 使用您喜欢的 IDE 远程调试 Java 插件

例如,在 Eclipse 中,选择 Run/Debug Configurations .../Remote Java Application

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

点击新建"按钮.

确保连接类型为Socket Attach",如果您的浏览器是本地的,请选择 localhost 作为主机,以及您之前选择的端口(示例中为 2502).

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).

您可能需要在源选项卡上的 JDK 中包含 src.zip 才能使用 Java 核心类源.

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

保存配置,一旦您的浏览器运行插件(无论 JVM 是否暂停),运行远程调试器以连接到插件 JVM,同时打开包含小程序源的项目.

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.

这篇关于设置用于小程序启动的默认 JVM 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆