Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Call Java from Shell Script --> Settings Classpath and Exectuing Java in different Shell Scripts

 
Florian Marquardt
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.

We are running serverl Java Jobs on a Linux maschine. They are started via a Shell Script.
If i have to modify the Classpath, i have to go through all sh Files and modify it.

Now i want to make my life easier and want to execute a Shell Script which set the Classpaht and one that execute the JavaClass.

I tried it, but when the first sh was executed, the Classpath is set back to default.
(Both ways i have tried --> Shell script runs after Shell Script and Shell Script calls Shell script)


Is there any possiblity to achieve this?

Thanks a lot

Florian
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This happens because when you run the shell script each one runs in its own session, and each uses its own set of env vars (there is no sharing). If you want to call a shell script an have it operate in the same session as the caller, then you have to "source" the script. One way to do that is with the "dot" command. Example:

child.sh:


parent.sh:


Or you can use the "source" command:


 
Florian Marquardt
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. The "source" worked!!!

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic