Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Linux script to call a java program

 
david lightman
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Chris De Vries
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic