#!/bin/bash
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk
CLASSPATH=/Users/sunny/CronTest/out/production/CronTest
$JAVA_HOME/Contents/Home/bin/java -cp $CLASSPATH ".:/Users/sunny/Downloads/sqlite-jdbc-3.8.11.2.jar" sample.Main
exit 0
Sqlite jar file is in /Users/sunny/Downloads/sqlite-jdbc-3.8.11.2.jar
Compiled java class file is in /Users/sunny/CronTest/out/production/CronTest/sample/Main.class
And I've set the cron job to be schedule at every 1 minute. Java class is getting exucuted but I am getting java.lang.ClassNotFoundException: org.sqlite.JDBC
Same command which is in script is working in terminal.
My question is how can I add jar file properly to be executed from shell script.
Seems there is a space in between your $CLASS PATH
and ".:/Users/sunny/Downloads/sqlite-jdbc-3.8.11.2.jar"
and missing a colon(:).
Please try with following with export
:
export CLASSPATH=.:/Users/sunny/CronTest/out/production/CronTest:/Users/sunny/Downloads/sqlite-jdbc-3.8.11.2.jar
and call java command with -cp $CLASSPATH
.
If it still not work, please try with -cp
directly:
$JAVA_HOME/Contents/Home/bin/java -cp ".:/Users/sunny/CronTest/out/production/CronTest:/Users/sunny/Downloads/sqlite-jdbc-3.8.11.2.jar" sample.Main
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.