I have problem trying to get my
java program invoke another Java application using Runtime.getRuntime().exec() on Linux platforms.
The Java application that I need to invoke requires a series of Jar files, application arguments, etc. in order to run. I can successfully run the application at the shell prompt but just could not run by invoking thru another java program.
The command that I try to run is somewhat like this:
java -Duser.dir=/myworkingdir -cp "app.jar:../lib/req1.jar:../lib/req2.jar:../lib/req2.jar" MyMainClass -a arga -b argb
I have tried using the exec(
String) but it couldn't run - keeps giving me NoClassDefFoundException: MyMainClass.
I've all tried to use exec(
new String[] {
"java",
"-Duser.dir=/myworkingdir",
"-cp",
"app.jar:../lib/req1.jar:../lib/req2.jar:../lib/req2.jar",
"MyMainClass",
"-a arga -b argb"
}) but it also gives the same error.
I hava also tried:
exec(
new String[] {
"java",
"-jar"
"-Duser.dir=/myworkingdir",
"-cp",
"app.jar:../lib/req1.jar:../lib/req2.jar:../lib/req2.jar",
"app.jar",
"-a arga -b argb"
})
The app starts but now it can't find some other classes from req1.jar.
I'm really have headaches on this problem. Could someone who knows how to solve this help me please?!!! Thanks!