I have a bash script that look like below. All I am doing here is trying to run a java program passing in classpath and other inputs.
[guest@server1]# cat runJava
#!/bin/bash
JARS=/home/guest/lib/*
CONFIG=/home/guest/AnalyticServer.properties
echo JARS=$JARS
echo CONFIG=$CONFIG
echo "java -cp \"$JARS\" com.test.ASDataSourceClient DELETE -c \"$CONFIG\" -n test_ds"
java -cp "$JARS" com.test.ASDataSourceClient DELETE -c "$CONFIG" -n test_ds
The java program runs perfectly fine when run directly on command line/terminal. I even tested running all the commands from above script on terminal directly(one by one) and verified that java program runs fine. However, when I launch these commands via script, I am having issue. It doesn't even seem to execute echo "java -cp .." command properly.
Could anyone advice what I may be missing.
[guest@server1]# bash runJava
JARS=/home/guest/lib/*
CONFIG=/home/guest/AnalyticServer.properties
" -n test_dsaSourceClient DELETE -c "/home/guest/AnalyticServer.properties
Exception in thread "main" java.lang.NoClassDefFoundError: com/test/ASDataSourceClient
Caused by: java.lang.ClassNotFoundException: com.test.ASDataSourceClient
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)
Could not find the main class: com.test.ASDataSourceClient. Program will exit.