简体   繁体   English

Java ProcessBuilder调试器Netbeans

[英]Java ProcessBuilder Debugger Netbeans

I am having trouble with the deeper layers of the JVM and its debugging functionality. 我在JVM的更深层及其调试功能方面遇到麻烦。 What I am trying to do is start a separate java program using ProcessBuilder and let it communicate with my main process. 我想做的是使用ProcessBuilder启动一个单独的Java程序,并使其与我的主进程通信。 All works fine unless I add the command 除非我添加命令,否则一切正常

"-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=1044", “-agentlib:JDWP = =运输dt_socket,服务器= Y,暂停= Y,地址= 1044”,

to the ProcessBuilder. 到ProcessBuilder。

Class toExecute = ExampleSimulationController.class;
String javaHome = System.getProperty("java.home");
String javaBin = javaHome
        + File.separator + "bin"
        + File.separator + "java";
String classpath = System.getProperty("java.class.path");
String className = toExecute.getCanonicalName();

ProcessBuilder builder = new ProcessBuilder(javaBin, "-cp",
        "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=1044",
         classpath, className);
builder.redirectErrorStream(true);

In adding this line to the ProcessBuilder (with the intention to add debugging functionality to the subprocess as described, for example, here: What are Java command line options to set to allow JVM to be remotely debugged? I get an exception when trying to read as follows: 在将此行添加到ProcessBuilder中时(例如,打算在子进程中添加调试功能,例如,在这里:设置哪些Java命令行选项以允许对JVM进行远程调试?尝试读取时出现异常)如下:

BufferedReader mainProcessConsoleOutput = new BufferedReader(new InputStreamReader(mainSimulation.getInputStream()));

and further down: 再往下走:

if(!(line = mainProcessConsoleOutput.readLine()).equals("someText"))

The exception is as follows: 异常如下:

Main Process: Exception in thread "main" java.lang.NoClassDefFoundError: /Users/...[path].../build/classes
Main Process: Caused by: java.lang.ClassNotFoundException: .Users.[same_Path].build.classes
Main Process:   at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
Main Process:   at java.security.AccessController.doPrivileged(Native Method)
Main Process:   at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
Main Process:   at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
Main Process:   at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
Main Process:   at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Exception in thread "main" java.lang.NullPointerException
at [PacketStructure].SimulationController.main(SimulationController.java:66)

I am using Netbeans as IDE and know about "Attaching a Debugger" and giving it the same port as specified in the command I pass to the ProcessBuilder. 我将Netbeans用作IDE,并且了解“附加调试器”并为其分配与我传递给ProcessBuilder的命令中指定的端口相同的端口。 However, I don't know when I have to do this - before I specify a breakpoint in the subprocess? 但是,我不知道何时需要执行此操作-在子流程中指定断点之前? Afterwards? 然后? So far I did not find any indication that my subprocess is communicating with a debugger in any way. 到目前为止,我还没有发现任何迹象表明我的子进程正在以任何方式与调试器进行通信。

What seems suspicious to me as well is the fact that the exception is thrown when I try to read from subprocess' stream - and not someplace earlier. 对我来说,似乎也很可疑的是,当我尝试从子流程的流中读取时抛出了异常,而不是更早的某个地方。

I do use ObjectInputStream and ObjectOutputStream to pass serialized data from one process to the other, but since I cannot debug the subprocess I don't know if that is a potential source of the problem. 我确实使用ObjectInputStream和ObjectOutputStream将序列化的数据从一个进程传递到另一个进程,但是由于无法调试子进程,因此我不知道这是否是问题的潜在根源。

I use MacOs. 我使用MacO。

Since the solution of this problem lies beyond my knowledge of the Java Magic, please help me in solving this riddle. 由于此问题的解决方案超出了我对Java Magic的了解,因此请帮助我解决这一难题。

Thanks, 谢谢,

M 中号

After a lot of time spent trying to solve the problem I finally did: 经过大量时间尝试解决问题后,我终于做到了:

ProcessBuilder builder = new ProcessBuilder(javaBin,"-agentlib:jdwp=transport=dt_socket,address=localhost:8000,server=n,suspend=y","-cp", classpath, className);

By adding the "-cp" command after the "-agentlib" command apparently the classpath is matched correctly with the className. 通过在“ -agentlib”命令之后添加“ -cp”命令,显然可以将classpath与className正确匹配。

Should I have known that the order in which commands are passed is important? 我是否应该知道传递命令的顺序很重要?

Thx 谢谢

classpath值必须紧随classpath参数之后。

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

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