Execution error java prog inside shell script

Execution error java prog inside shell script

Post by Martin Caldwe » Sat, 19 Feb 2005 07:36:18



When I execute a java program from the command line

/test/mypath>java myprog

everything is fine. If I put the same statement into shell script (in the same directory)
the execution fails with an error

Exception in thread "main" java.lang.NoClassDefFoundError: /test/mypath/myprog

What's wrong?

Martin

 
 
 

Execution error java prog inside shell script

Post by Heiner Steve » Sat, 19 Feb 2005 07:57:45



> When I execute a java program from the command line

> /test/mypath>java myprog

> everything is fine. If I put the same statement into shell script (in the same directory)
> the execution fails with an error

> Exception in thread "main" java.lang.NoClassDefFoundError: /test/mypath/myprog

> What's wrong?

Maybe your CLASSPATH is set correctly, but not exported (using "export
CLASSPATH")? In this case the current shell had the right settings
for CLASSPATH, but any subshell (e.g. a shell script) would not
get the settings exported, but get e.g. an empty CLASSPATH.

Heiner
--
  ___ _

\__ \  _/ -_) V / -_) ' \    Shell Script Programmers: visit
|___/\__\___|\_/\___|_||_|   http://www.shelldorado.com/

 
 
 

Execution error java prog inside shell script

Post by weaselboy197 » Sat, 19 Feb 2005 22:52:23



> When I execute a java program from the command line

> /test/mypath>java myprog

> everything is fine. If I put the same statement into shell script (in
the same directory)
> the execution fails with an error

> Exception in thread "main" java.lang.NoClassDefFoundError:
/test/mypath/myprog

> What's wrong?

> Martin

The environment variables aren't passed to your script.  Try setting or
exporting PATH and CLASSPATH in your script.
 
 
 

1. Shell script hangs at execution of Java program...

So, my java code appears to run to completion b/c I can see the output
of the last executable line of my Java program in my log file.  It
seems to be a case of the Java program not returning control back to
the shell script.  The last line of code is a
'System.out.println("Ending...")'.  But, 12 hours later, I can still
see the two processes running - the shell script and the child Java
process.  I run this shell script from a cron job usually, but it can
hang when run from an interactive shell as well.

The script seems to run fine 90+% of the time.

The particular java code does a lot of ftp stuff using a 3rd party
library.  I don't know of any open file handles, etc.  No db
connections.  I'm thinking of adding a call to System.exit(0), maybe
even a 'finally' block.  I have other shell scripts running other Java
programs dealing w/ all sorts of stuff - filesystem, db, mail, but
none seem to hang.

Here's my system:

$ uname -a
HP-UX etc-rp11 B.11.11 U 9000/800

Any ideas??

-------------------------------------------------

## Here's the crontab task
/path/to/myscript.sh >> /path/to/mylog.log 2>&1

-------------------------------------------------
## And here's the shell script
echo "========== $0 starting on `date`... =========="

# Create lockfile
mkdir $lockfile

# Run Java program
java -cp $CLASSPATH MyClass

# Remove lockfile
rmdir $lockfile

echo "========== $0 ending on `date`... =========="

-------------------------------------------------

2. Allow Specific IP only

3. Execution of SQL Script thru shell script

4. Internal Zip Drive, 2 SCSI cards and LILO

5. How to find other copies of same shell script running inside shell?

6. Clean shutdown method under XDM

7. Executing shell commands from inside a Java application

8. "Wild Interrupt" / Soundblaster problem

9. Java, Java, Java, Java, Java, Java .....

10. Interfacing a c prog with a shell prog

11. How Can I control program execution in script shell ?

12. >> Shell Script Execution Question

13. Shell script execution when mail is recieved