I am having a java process which needs to be always running. I have written the following shell in cron program to check that java process:
if [ `ps aux | grep testjava | grep -v grep | wc -l` -ne 1 ];then
cd /root/folder
sh mytest.sh >test.log 2>test-err.log &
echo "mytest not running and restarted on "`date` >> /root/check-test.log
where mytest.sh
contains the java class which has to be running.
When I execute the shell file separately it executes well. But when I execute the above cron it gives me the following exception :
Exception in thread "main" java.lang.NoClassDefFoundError: mytest/mytestprog
Caused by: java.lang.ClassNotFoundException: mytest.mytestprog
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Where i am going wrong .
Edit:
I run the mytest.sh file with the path as $JAVA_HOME/bin/java -cp .:/root/lib/* -Djava.rmi.server.codebase=file:/root/folder/ -Djava.rmi.server.hostname=hostnameip -Djava.security.policy=server.policy -Xmx512m -Xms512m mytest.mytestprog