javadebuggingclasspathconnectorlaunching

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. 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. It requires arguments of class 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. In my case, that is "debuggee.DebuggerTest". The program that invokes the launch has main class "debugger.TraceLaunch".

My Eclipse project has the default structure, so there is a folder named "classes" with a subfolder for each package. In my case, those are "com", "debugger", and "debuggee". The "com" package includes all the classes from "Example JDI Applications".

I am using "VMLauncher", referenced in the post cited above, to do the launching. The launch fails; it reports that my main class "debuggee.DebuggerTest" cannot be found. 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. I can also launch the debugger with the command "java debugger.TraceLaunch", and it in turn successfully launches the debuggee. This suggests that VMLauncher is doing all the right things.

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. It seems to be of class 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.

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

Ideally, I'd like to know how to specify a classpath to a 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.


Solution

  • The new VM which is created by the Trace has different class path. If you want to run the program in eclipse you need to add the following code in your trace program.

    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.

    It is worked for me.