Run the application and capture its in/out streams, then stream the serialized object model through it. The new application should deserialize input coming from System.in .
Example of the concept (I just wanted to make sure my example works, sorry for the delay):
package tests;
import java.io.File;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public class AppFirst {
public static void main(String[] args) throws Exception {
ProcessBuilder pb = new ProcessBuilder("java", "-cp",
"./bin", "tests.AppSecond");
pb.directory(new File("."));
pb.redirectErrorStream(true);
Process proc = pb.start();
ObjectOutputStream out = new ObjectOutputStream(
proc.getOutputStream());
ObjectInputStream oin = null;
for (int i = 0; i < 1000; i++) {
out.writeObject("Hello world " + i);
out.flush();
if (oin == null) {
oin = new ObjectInputStream(proc.getInputStream());
}
String s = (String)oin.readObject();
System.out.println(s);
}
out.writeObject("Stop");
out.flush();
proc.waitFor();
}
}
package tests;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public class AppSecond {
public static void main(String[] args) throws Exception {
ObjectInputStream oin = null;
ObjectOutputStream out = new ObjectOutputStream(System.out);
while (true) {
if (oin == null) {
oin = new ObjectInputStream(System.in);
}
String s = (String)oin.readObject();
if ("Stop".equals(s)) {
break;
}
out.writeObject("Received: " + s);
out.flush();
}
}
}
Edit: Added a looping version. Note that there needs to be a trick with the OOS, as it instantly starts to read the passed in stream (and blocks your app If you do it at the wrong step - it should be wrapped AFTER the first object is sent out to the child process).