File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Linux script to call a java program" Watch "Linux script to call a java program" New topic

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?

Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

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.

[ April 19, 2005: Message edited by: Chris De Vries ]
I agree. Here's the link:
subject: Linux script to call a java program
jQuery in Action, 3rd edition