Tux

...making Linux just a little more fun!

Run java class file using cron?

Mudassar Khan [mudassar at jumpgames.co.in]


Wed, 14 Nov 2007 16:20:33 +0530

[[[ I've retitled this thread from its original "query" title to something more descriptive. -- Kat ]]]

Hi, Can I run java class file using cron. If yes. then help me. Regards, Mudassar Khan


Top    Back


Thomas Adam [thomas.adam22 at gmail.com]


Wed, 14 Nov 2007 11:04:37 +0000

Hello --

On 14/11/2007, Mudassar Khan <mudassar@jumpgames.co.in> wrote:

>
> Hi,
>
>        Can I run java class file using cron.

Again what the HTML. Stop it.

Yes you can run a java class file with cron.

java somefile
Assumes you have $JAVA_HOME set correctly which you will need to do within the crontab file due to how cron clobbers the environment it runs under.

-- Thomas Adam


Top    Back


Mudassar Khan [mudassar at jumpgames.co.in]


Thu, 15 Nov 2007 15:29:44 +0530

Hi Thomas, I m not able to run java class file in cron.

I have set my crontab like this..

          * * * * * java /opt/javafiles/Movefile >> /tmp/t.log
but I got following error.
   Exception in thread "main" java.lang.NoClassDefFoundError:
.opt.javafiles.Movefile
   at gnu.gcj.runtime.FirstThread.run() (/usr/lib/libgcj.so.5.0.0)
   at _Jv_ThreadRun(java.lang.Thread) (/usr/lib/libgcj.so.5.0.0)
   at _Jv_RunMain(java.lang.Class, byte const, int, byte const, boolean)
(/usr/lib/libgcj.so.5.0.0)
   at __gcj_personality_v0 (/root/java.version=1.4.2)
   at __libc_start_main (/lib/tls/libc-2.3.4.so)
   at _Jv_RegisterClasses (/root/java.version=1.4.2)
Can you help me..?

Regards, Mudassar Khan


Top    Back


Thomas Adam [thomas.adam22 at gmail.com]


Thu, 15 Nov 2007 12:12:35 +0000

Hello --

Do you somehow not understand how email works? You should reply to the thread you started, and not create a new one, especially since your reply has relevance.

[[[ Thankfully, the thread was not renamed, just not replied to properly, so it wasn't hard to reconcile. Still, thanks for pointing that out, Thomas! -- Kat ]]]

On 15/11/2007, Mudassar Khan <mudassar@jumpgames.co.in> wrote:

> Hi Thomas,
>           I m not able to run java class file in cron.
>
>           I have set my crontab like this..
>
>           * * * * * java /opt/javafiles/Movefile >> /tmp/t.log

This is bad. This will continually run the specified program, not to mention potentially fill up /tmp very quickly if it contains any data.

>           but I got following error.
>
>    Exception in thread "main" java.lang.NoClassDefFoundError:
> .opt.javafiles.Movefile
>    at gnu.gcj.runtime.FirstThread.run() (/usr/lib/libgcj.so.5.0.0)

Install the JRE from Sun, and not use the GNU stuff. My reply to you from before about JAVA_HOME also applies here.

-- Thomas Adam


Top    Back


Trevor Pearson [trevor at haven.demon.co.uk]


Fri, 16 Nov 2007 22:29:30 +0000

Thomas Adam wrote:

> Hello --
>
> Do you somehow not understand how email works?  You should reply to
> the thread you started, and not create a new one, especially since you
> reply has relevance.
>
> On 15/11/2007, Mudassar Khan <mudassar@jumpgames.co.in> wrote:
>   
>> Hi Thomas,
>>           I m not able to run java class file in cron.
>>
>>           I have set my crontab like this..
>>
>>           * * * * * java /opt/javafiles/Movefile >> /tmp/t.log
>>     
>
> This is bad.   This will continually run the specified program, not to
> mention potentially fill up /tmp very quickly if it contains any data.

This is also going to fail because java (sun java, I haven't tested gnu) does not allow a path to be specified like this only a java class name. you need to run a command like this

java -cp /opt/javafiles movefiles 
using the 'classpath' switch to specify a path if the class file is in a directory that is not in your CLASSPATH environment variable.

>>           but I got following error.
>>
>>    Exception in thread "main" java.lang.NoClassDefFoundError:
>> .opt.javafiles.Movefile
>>    at gnu.gcj.runtime.FirstThread.run() (/usr/lib/libgcj.so.5.0.0)
>

This error translates as 'didn't find the file' since java has helpfully searched your current directory and CLASSPATH directories for a file called '.opt.javafiles.Movefile.class' . This behaviour must have seemed a sensible idea to someone at sun :)


Top    Back