I have a small programm and several .sh files to execute it. I use Raspberry-pi virtual box emulator to run it. (Don’t ask why… just need it.. 🙂 )
So, my .sh file looks like:
export HSQLDB_JAR=../lib/hsqldb-2.2.8.jar
java -classpath $HSQLDB_JAR org.hsqldb.Server -database.0 ../my-hsqldb/my-hsqldb -dbname.0 my-hsqldb
I have the needed jars, java is installed properly (checked several times), blah-blah, all the same:
rpi@RaspberryPi:/home/snb/my/apps/MyApp/bin$ sh skysql.sh
: not found2:
Exception in thread "main" java.lang.NoClassDefFoundError: org/hsqldb/Server
Caused by: java.lang.ClassNotFoundException: org.hsqldb.Server
The most interesting thing, that when I run the script from the sh file directly from bash – it works! But running the .sh file gives this error 🙁
Any help is very appreciated.
EDIT
The following directories have all of the access rules, so no security issues could happen. They are all accessible.
EDIT #2
I have used the offered answers and comments and that’s what happened:
-
Still same stuff 🙁
-
My .sh file:
#!/bin/bash export HSQLDB_JAR="$(pwd)/hsqldb-2.2.8.jar" echo $HSQLDB_JAR java -classpath $HSQLDB_JAR org.hsqldb.Server -database.0 ../my-hsqldb/my-hsqldb -dbname.0 my-hsqldb
The terminal output is:
rpi@RaspberryPi:/home/snb/my/apps/MyApp/bin$ sh skysql.sh
: not found2:
: not found4:
/home/snb/my/apps/MyApp/lib/hsqldb-2.2.8.jar
: not found6:
Exception in thread "main" java.lang.NoClassDefFoundError: org/hsqldb/Server
Caused by: java.lang.ClassNotFoundException: org.hsqldb.Server
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: org.hsqldb.Server. Program will exit.
: not found8:
So, as you can see, the .jar is actually found and it is in the right path.
This is probably a bug in a part of the script that you don’t show. Try this:
Make sure the first line of your script reads
#!/bin/bashMake sure you’re in the folder that you think you are. Add
before calling
javaTo see what the shell actually executes, use
-x(either add-xas parameter to the first line or activate it with the commandset -x).If you need to generate a path relative to your script, use this code:
Always quote variables which contain paths to make sure white space works properly.