How to stop java application using a shell script

Posted by Fernando Moyano on Stack Overflow See other posts from Stack Overflow or by Fernando Moyano
Published on 2012-03-29T23:16:04Z Indexed on 2012/03/29 23:29 UTC
Read the original article Hit count: 326

Filed under:
|

I have a shell script, which is run under a opensuse linux, that starts a java application (under a jar), the script is:

#!/bin/sh

#export JAVA_HOME=/usr/local/java
#PATH=/usr/local/java/bin:${PATH}

#---------------------------------#
# dynamically build the classpath #
#---------------------------------#
THE_CLASSPATH=
for i in `ls ./lib/*.jar`
do
  THE_CLASSPATH=${THE_CLASSPATH}:${i}
done

#---------------------------#
# run the application #
#---------------------------#
java -server -Xms512M -Xmx1G -cp ".:${THE_CLASSPATH}"  com.package.MyApp > myApp.out 2>&0 &   

This script is working fine.

Now, what I want, is to write a script to kill gracefully this app, something that allows me to kill it with the -15 argument from Linux kill command.

The problem, is that there will be many java applications running on this server, so I need to specifically kill this one.

Any help?

Thanks in advance,

Fernando

© Stack Overflow or respective owner

Related posts about java

Related posts about shell