jQuery in Action, 3rd edition
The moose likes Linux / UNIX and the fly likes starting a servlet when the server startup Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "starting a servlet when the server startup" Watch "starting a servlet when the server startup" New topic

starting a servlet when the server startup

preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
I need to start my java program automatically during linux server starts.I have done the coding.But when i tried to start using the command "service api start",It is showing the following error:

/etc/init.d/api: line 11: -classpath: command not found
Cannot start API server

line 11 is:

st=java -classpath mysql-connector-java-3.0.17-ga-bin.jar:.:asterisk-java-0.3.1.jar HelloEvents

I dont know how to solve this.please assist me.
[ June 30, 2008: Message edited by: preethi Ayyappan ]
Rodrigo Tomita
Ranch Hand

Joined: Apr 28, 2008
Posts: 70

Perhaps you get better luck in a Unix (or Linux) forum, but here goes my 2 cents. This is what I got from your post: /etc/init.d/api is your service script. Inside the script you are defining a variable called st with the command line you want to execute.

However, you have spaces in your command line so it is not recognizing the entire line as the value of the variable. It should work if you put single quotes around it like:

Hope it helps.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17276

Rodrigo is correct. It's a good practice in shell scripts to capitalize variable names, however:

You may also want to use double quotes so that you can take advantage of variable substitutions:

This can make things a bit more manageable when using long jar paths, supporting alternative jars (especially database drivers) or testing version upgrades.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link: http://aspose.com/file-tools
subject: starting a servlet when the server startup
It's not a secret anymore!