File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

process has not exited

 
Madhu Bala
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

I am using Runtime class in my application.It creates JAR & EAR Files.For that I used Runtime class.
Here my peace of code Pls help me what is worng in this code.


try {
String stmt = "jar -Mcvf " + ejbJarName + " META-INF/MANIFEST.MF " +" META-INF/ejb-jar.xml " + " com";
Process stmtProcess = java.lang.Runtime.getRuntime().exec(stmt);
if (osname.startsWith("Windows")) {
System.out.println("use Thread.sleep(" + ntdepltime + ")");
Thread.sleep(100000);
try
{
stmtProcess.exitValue();
}catch(IllegalThreadStateException exp){ System.out.println("Madhu exception "+exp); }
} else {
System.out.println("use waitFor()");
stmtProcess.waitFor();
}
stmt = "jar -Mcvf " + newEarName + " META-INF/MANIFEST.MF " +" META-INF/application.xml " + ejbJarName + " " + clientJarName;
stmtProcess = java.lang.Runtime.getRuntime().exec(stmt);
if (osname.startsWith("Windows")) {
System.out.println("use Thread.sleep(" + ntdepltime + ")");
Thread.sleep(100000);
} else {
System.out.println("use waitFor()");
stmtProcess.waitFor();
}
} catch (Exception e) {
e.printStackTrace();
}

After JAR file creatation execution it is throwing java.lang.IllegalThreadStateException exception.

Pls help me in this regard.

thanks,
Madhu
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Put your sleep in a synchronized block as shown in THIS thread.

I'm curious why you don't trust waitFor in Windows. Are there known issues with that?

You might also search this thread for StreamGobbler. There were some good examples of reading stdout and errout from the process. I only did all this stuff once and I waited for the outputs to end rather than using waitFor(). The streams seemed to run a while after waitFor returned, maybe because they were buffered or something.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic