Forums Register Login

Running a Java Class from a Unix Shell Script

+Pie Number of slices to send: Send
I'm having a very unusual problem. I have a java class that does operations on a database. I've made a Windows batch file that successfully runs this java class. Unfortunately, I can't get it to run off a unix shell. I can run a HelloWorld program using a hello.sh no problem.
From the command prompt, I ran:
java -cp hsql.jar:. DropTables
and it worked.
I then created a shell script DropDB.sh with these contents:
java -cp hsql.jar:. DropTables
Running DropDB.sh, I got the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: DropTables
What am I doing wrong? I tried putting in the absolute path instead of the dot, and it still didn't work.
+Pie Number of slices to send: Send
 

Originally posted by Gabriel Cane:
I'm having a very unusual problem. I have a java class that does operations on a database. I've made a Windows batch file that successfully runs this java class. Unfortunately, I can't get it to run off a unix shell. I can run a HelloWorld program using a hello.sh no problem.
From the command prompt, I ran:
java -cp hsql.jar:. DropTables
and it worked.
I then created a shell script DropDB.sh with these contents:
java -cp hsql.jar:. DropTables
Running DropDB.sh, I got the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: DropTables
What am I doing wrong? I tried putting in the absolute path instead of the dot, and it still didn't work.


I believe a ";" is required instead of a ":" as a separator for -cp paths.
+Pie Number of slices to send: Send
 

Originally posted by Rob Levo:

I believe a ";" is required instead of a ":" as a separator for -cp paths.


No, in unix, the classpaths are separated by ":".
+Pie Number of slices to send: Send
I solved the problem.
I had the boneheaded idea of copying my Windows batch file to a shell script file and then editing it. What I should have done instead was to create a brand new file in Linux and then add the command to that file.
My shell scripts now run the way they're supposed to.
+Pie Number of slices to send: Send
Hello, I want to know the internal process of running a java program from shell script. I want to run a java program (residing in iPlanet webserver) from the shell script. Will the shell script invoke a seperate JVM to run this java program? What happens internally? Anybody please explain.
Thanks
Kiran
Climb the rope! CLIMB THE ROPE! You too tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 11011 times.
Similar Threads
issue when calling shell script from java
FTP
running java program from a shell script
Applets and shell scripts
Class Not Found exception in cron job
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 13:24:28.