• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Invoking a Java app from a Java app on LInux

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!

 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happen when you invoke the java application directly? I mean you issue in command line instead of using Runtime class? If you can invoke the app from command line, then you can concentrate to debug your programm that does the invocation. I guess it is very likely you need to give the full path in exec("Fullpath"). I don't know why you need full path. I had similar problem before and it was solved when i issued full path.
 
Lois Neo
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The app can be invoked at command line.
What do you mean by exec("fullpath")?
I have tried hard-coding the fullpaths of the jars I include in the classpath option, but still gives ClassDefNotFoundException.
I have also tried with the other method exec(cmd, env).
I specify the CLASSPATH=<myclasspath> in the env. Doing this the app can be invoked but another problem crops up:
In the java application that is invoked, it happens that yet another java app need to be invoked. however now the system complains that "java" was not found. I suspect that by passing in the environment settings, it has overwritten the second process does not inherit the environment settings from the first process anymore. Is there anyway to retain the environment settings of the parent process, while able to specify what env variable that I want to override? Thanks.
 
So I left, I came home, and I ate some pie. And then I read this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic