File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Linux / UNIX and the fly likes Call Java from Shell Script --> Settings Classpath and Exectuing Java in different Shell Scripts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Call Java from Shell Script --> Settings Classpath and Exectuing Java in different Shell Scripts" Watch "Call Java from Shell Script --> Settings Classpath and Exectuing Java in different Shell Scripts" New topic
Author

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

Florian Marquardt
Greenhorn

Joined: Apr 19, 2007
Posts: 6
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

Joined: May 14, 2008
Posts: 5838
    
    7

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:



JBoss In Action
Florian Marquardt
Greenhorn

Joined: Apr 19, 2007
Posts: 6
Thank you. The "source" worked!!!

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Call Java from Shell Script --> Settings Classpath and Exectuing Java in different Shell Scripts