File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Running a Java Class from a Unix Shell Script Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Running a Java Class from a Unix Shell Script" Watch "Running a Java Class from a Unix Shell Script" New topic
Author

Running a Java Class from a Unix Shell Script

Gabriel Cane
Ranch Hand

Joined: Mar 27, 2001
Posts: 39
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.


Sun Certified Programmer for the Java 2 Platform
Rob Levo
Ranch Hand

Joined: Oct 01, 2000
Posts: 167
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.
Gabriel Cane
Ranch Hand

Joined: Mar 27, 2001
Posts: 39
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 ":".
Gabriel Cane
Ranch Hand

Joined: Mar 27, 2001
Posts: 39
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.
kiran kiran
Greenhorn

Joined: Dec 04, 2003
Posts: 12
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Running a Java Class from a Unix Shell Script