I am having trouble with the deeper layers of the JVM and its debugging functionality. What I am trying to do is start a separate java program using ProcessBuilder and let it communicate with my main process. All works fine unless I add the command
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=1044",
to the 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:
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. 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.
I use MacOs.
Since the solution of this problem lies beyond my knowledge of the Java Magic, please help me in solving this riddle.
Thanks,
M
The classpath value must immediately follow the classpath argument.