简体   繁体   English

如何为JDI启动连接器指定类路径;用Eclipse?

[英]How do I specify the classpath for a JDI launching connector; using Eclipse?

I'm doing essentially the same thing as the original poster of this question . 我做的基本上和这个问题的原始海报一样。 In my case, I'm trying to run the Sun/Oracle JPDA example programs in Eclipse Kepler on OS X 10.8.5, with Oracle jdk1.7.0_72. 就我而言,我正在尝试使用Oracle jdk1.7.0_72在OS X 10.8.5上的Eclipse Kepler中运行Sun / Oracle JPDA示例程序。 However, the documentation for those examples seems to assume they will be run from the command line. 但是,这些示例的文档似乎假设它们将从命令行运行。

I want to use com.sun.jdi.connect.LaunchingConnector to launch the debuggee program. 我想使用com.sun.jdi.connect.LaunchingConnector来启动debuggee程序。 It requires arguments of class Map <String, Argument>. 它需要类Map <String,Argument>的参数。 One of the map entries has key "main" and its associated object contains a String that is the debuggee main class name. 其中一个映射条目具有键“main”,其关联对象包含一个String,它是调试对象的主类名。 In my case, that is "debuggee.DebuggerTest". 就我而言,那就是“debuggee.DebuggerTest”。 The program that invokes the launch has main class "debugger.TraceLaunch". 调用启动的程序有主类“debugger.TraceLaunch”。

My Eclipse project has the default structure, so there is a folder named "classes" with a subfolder for each package. 我的Eclipse项目具有默认结构,因此有一个名为“classes”的文件夹,每个包都有一个子文件夹。 In my case, those are "com", "debugger", and "debuggee". 在我的例子中,那些是“com”,“调试器”和“调试对象”。 The "com" package includes all the classes from " Example JDI Applications ". “com”包包括“ Example JDI Applications ”中的所有类。

I am using " VMLauncher ", referenced in the post cited above, to do the launching. 我正在使用上面引用的帖子中引用的“ VMLauncher ”来进行启动。 The launch fails; 发射失败; it reports that my main class "debuggee.DebuggerTest" cannot be found. 它报告无法找到我的主类“debuggee.DebuggerTest”。 It also fails if I try to include the full path as part of my main class name. 如果我尝试将完整路径包含在我的主类名中,它也会失败。

If I open a terminal and export a CLASSPATH variable that specifies the "classes" folder inside my Eclipse project (and the JDI library), I can launch the debuggee with the command "java debuggee.DebuggerTest" and it runs correctly. 如果我打开一个终端并导出一个CLASSPATH变量,该变量指定我的Eclipse项目(和JDI库)中的“classes”文件夹,我可以使用命令“java debuggee.DebuggerTest”启动调试对象并且它可以正确运行。 I can also launch the debugger with the command "java debugger.TraceLaunch", and it in turn successfully launches the debuggee. 我也可以使用命令“java debugger.TraceLaunch”启动调试器,然后它成功启动调试对象。 This suggests that VMLauncher is doing all the right things. 这表明VMLauncher正在做所有正确的事情。

So it seems that the problem is that somewhere deep in the examples packages or the JDI packages from Oracle's "tools.jar", the LaunchingConnector invokes a command line launcher. 因此,似乎问题是在示例包中的某个地方或Oracle的“tools.jar”中的JDI包中,LaunchingConnector调用命令行启动器。 It seems to be of class SunCommandLineLauncher. 它似乎属于SunCommandLineLauncher类。 That launcher seems to assume a classpath. 那个发射器似乎假设了一个类路径。 The launcher arguments don't seem to be documented, so I don't know if there is an option to specify a classpath. 启动器参数似乎没有记录,所以我不知道是否有指定类路径的选项。 The source code for the Oracle jdk1.7.0 JDI classes (in "lib/tools.jar") has apparently not been published, so I can't look at the code for the details of how the launcher uses its arguments. Oracle jdk1.7.0 JDI类(在“lib / tools.jar”中)的源代码显然尚未发布,因此我无法查看代码以了解启动程序如何使用其参数的详细信息。

One other clue that may be helpful: in the example JDI applications, the GUI debugger example allows specifying a classpath, which it tries to parse. 另一个可能有用的线索:在示例JDI应用程序中,GUI调试器示例允许指定它尝试解析的类路径。 Unfortunately, it does not recognize quoting or character-escaping like a UNIX shell does, and it does not understand folder names that include a space character. 不幸的是,它不像UNIX shell那样识别引用或字符转义,并且它不理解包含空格字符的文件夹名称。

Ideally, I'd like to know how to specify a classpath to a LaunchingConnector. 理想情况下,我想知道如何指定LaunchingConnector的类路径。

My second choice would be some more general suggestions for how to specify a classpath when adapting a command line program to run in Eclipse. 我的第二个选择是在调整命令行程序以在Eclipse中运行时如何指定类路径的一些更一般的建议。

The new VM which is created by the Trace has different class path. Trace创建的新VM具有不同的类路径。 If you want to run the program in eclipse you need to add the following code in your trace program. 如果要在eclipse中运行该程序,则需要在跟踪程序中添加以下代码。

Connector.Argument options =(Connector.Argument)arguments.get("options");
options.setValue("-cp \"F:\\Workspace\\TraceProgram\\bin\"");

Where -cp set the class path to newly created VM, you need to change to your eclipse work directory. where -cp设置新创建的VM的类路径,您需要更改到您的eclipse工作目录。

It is worked for me. 这对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM