I am not really a beginner, but I am fairly sure this is a simple question, and I am just missing something simple.
I am running a web server on a VPS. I want to check if there are any new files on the server and if there are, add some records to a database. I have writen a java app. and a script  that sets the CLASSPATH and runs the app. This runs fine from the command line, but fails when run as a cron job. I have writen a little test app. that demonstates the problem . The exception is at  with some more debugging info from the script.
 email@example.com [~/public_html]# ll /home/server/lib/mysql-connector-java-3.0.15-ga-bin.jar -rwxrwxrwx 1 server server 235712 Aug 7 13:17 /home/server/lib/mysql-connector-java-3.0.15-ga-bin.jar*
[ August 09, 2006: Message edited by: Huw Morgan ] [ August 09, 2006: Message edited by: Huw Morgan ]
I've seen this, check the permissions on the /home/server/lib/mysql-connector-java-3.0.15-ga-bin.jar and the folders leading to it. If the user that is running the Cron jobs doesn't have read permission on everything, you can get this.
As I posted in  above, I have put a copy of the .jar in a directory owned by the user "server", and it has all permisions (-rwxrwxrwx 1 server server 235712 Aug 7 13:17 /home/server/lib/mysql-connector-java-3.0.15-ga-bin.jar).
I have put whoami in the script, and this returns "server", so it must be that user who is running it.
One thought on why your solution worked. It has been a while since I played with UNIX, but I seem to recall having a similar issue going from running a script manually to running it in the cron task. The issue, as I recall, appeared to be that the classpath was never picked up from the shell script by the java routine.
Try doing an "export" of the CLASSPATH environmental variable. I believe the issue came down to either a problem being allowed to set the environmental variable or the need for the CLASSPATH to be known outside of the shell.
Joined: Feb 18, 2005
Exactly what Terry said.
Without the export statements, the environment variables set in the shell script do make it into the JVM process.
If you were using bash, you could do the assignment and export in one command: export CLSSPATH=blah blah blah