S. D. Smith S. D. Smith -4 years ago 214
Java Question

How to run a Java program under cron and import the jars

My source file is

. The jar files are under
. The jar files are from HTMLUnit 2.10.

This is the source for my cron file:

0 0 * * * java -classpath .../MyDir/proj/ myProj

But it gave me the error:

Exception in thread "main" java.lang.NoClassDefFoundError: com/gargoylesoftware/htmlunit/WebClient

How do I modify the cron file to import the jar files?

Answer Source

Something like this:

0 0 * * * java -classpath .../MyDir/proj/:.../MyDir/proj/library/jar1.jar:.../MyDir/proj/library/jar2.jar myProj

or if you are using a recent JVM you can use a wildcard to match all of the JAR files.

0 0 * * * java -classpath .../MyDir/proj/:.../MyDir/proj/library/\* myProj

(The backslash is probably unnecessary because 'globbing' is unlikely to match anything in that context ...)

Better still, put the command (and any others that need to be run to prepare for the launch) into a shell script, and run the script from your crontab entry instead.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download