Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Running a Java Class from a Unix Shell Script

 
Gabriel Cane
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Levo
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic