wood burning stoves 2.0*
The moose likes Linux / UNIX and the fly likes Linux script to call a java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Linux script to call a java program" Watch "Linux script to call a java program" New topic
Author

Linux script to call a java program

david lightman
Ranch Hand

Joined: Nov 03, 2004
Posts: 82
I am a linux newbie but I want to call java program from a script that I would to run at startup. ( place in /rc?)

it is a bash shell and is it also possible to pass variables to the java program when it is called?

thanks
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Looks like I already answered part of this here. Please don't post the same question to multiple forums -- it just wastes people's time.


[Jess in Action][AskingGoodQuestions]
Chris De Vries
Ranch Hand

Joined: Dec 05, 2002
Posts: 65
I have written a couple of shell scripts to run command line java programs from linux. One of the benefits I've found is that I can pass additional arguments to the jvm and use the script to pass environment variables to the jvm as system properties. Here's an example script I wrote:



This illustrates both features I described earlier. I have set the maximum heap size to 256 megabytes, and the script checks for the existance of the environment variable MOLDATA which it passes to the property devries.radxfer.moldata if it exists. the "$@" means insert the script's command line arguments here.

To create an rc script I would take a look at your system's init.d scripts and use a similar format. Debian provides /etc/init.d/skeleton as an example init.d script which uses their start-stop-daemon program to start and stop your daemon.

Good luck.

Chris
[ April 19, 2005: Message edited by: Chris De Vries ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Linux script to call a java program
 
Similar Threads
Calling shell script
Get the UNIX process ID of the java program
Simple TAR
runtime exec
call java program from script?