• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Running a Java Class from a Unix Shell Script  RSS feed

 
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.
 
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.
 
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!