Arnold Cristobal
Arnold Cristobal

Reputation: 851

java class main error for crontab

When I try to run the exe jar file in unix:

$ java -jar /tnpm_pm_test.jar

It runs properly without any errors but when I try to add it in a crontab

*/15 * * * * /usr/bin/java java -jar /home/user1/tnpm/tnpm_pm_test.jar &> /dev/null

I'm getting the error below:

Exception in thread "main" java.lang.NoClassDefFoundError: version
Caused by: java.lang.ClassNotFoundException: version
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
Could not find the main class: version. Program will exit.

I'm not sure what exaclty is the difference between running it independently and using crontab. Anyone knows?

whereis java = java: /usr/bin/java /etc/java /usr/lib/java /usr/share/java
which java = /usr/bin/java

Upvotes: 0

Views: 383

Answers (2)

booboo
booboo

Reputation: 110

You have to be an administrator to put the output into /dev/null. So put it into a file in your home directory and add an entry to the crontab to delete the file occasionally.

Upvotes: 0

Kumar
Kumar

Reputation: 4010

refer this link.

I think the below command will run correctly. Make sure all your dependency jar files in the path /home/user1/tnpm/

0/15 * * * * java -jar /home/user1/tnpm/tnpm_pm_test.jar &> /dev/null
or
0/15 * * * * /usr/bin/java -jar /home/user1/tnpm/tnpm_pm_test.jar &> /dev/null

Upvotes: 1

Related Questions