Results 1 to 8 of 8
  1. #1
    rockie12 is offline Member
    Join Date
    Nov 2007
    Posts
    3
    Rep Power
    0

    Default how to run java app on windows in a cron like on unix

    I am trying to run a java program every 10 minutes on my windows PC. If I run the program manually all works fine...

    java myProgramName

    Since windows does not support crontab type functionality, I have installed pycron and it runs my program every ten minutes, but I get a class not found error.

    I have tried

    0,10,20,30,40,50 * * * * javaw myPackage.com.myProgram


    I have added my program to the system environment variable CLASSPATH, but still no success.

    Any thoughts on how I can set up cron on windows to run my java application?

    Thanks in advance for your assistance
    Dean-O

  2. #2
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    10

    Default

    Try to create a bat file. Set JAVA_BIN path there and call interpreter with full path in the bat file (e.g. $JAVA_BIN$\java.exe YourClass) Test it by running bat file manually and then try to run bat file via cron.

  3. #3
    rockie12 is offline Member
    Join Date
    Nov 2007
    Posts
    3
    Rep Power
    0

    Default

    I have tried the bat file option too, but I get the same class not found error ir I run the bat file from the pycron. If I run the bat file manually, all is fine. Maybe it has to do with pycron... it is an NT service that is running as local system administrator... maybe the user does not get the CLASSPATH variable...

    How would one run a java application on a windows machine in a crontab like manner as one would on a unix box?

    Thanks
    Dean-O

  4. #4
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    10

    Default

    Can you post the bat file you created? I am not sure if you set classpath variable too in your bat file.

  5. #5
    rockie12 is offline Member
    Join Date
    Nov 2007
    Posts
    3
    Rep Power
    0

    Default

    javaw.exe -Xmx300m -classpath ".;C:\MailProgram;C:\Program Files\Java\jre1.5.0_06\lib\ext\mail.jar;C:\Program Files\Java\jre1.5.0_06\lib\ext\activation.jar" myapps.com.showMail

  6. #6
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    10

    Default

    My suggestion is to define CLASSPATH as an environment variable and JAVA_BIN path inside bat file before calling and javaw.exe. I have Vista and i dont have CLASSPATH environment variable. But as far as i remember, in XP and below there was a globally defined CLASSPATH environment variable. Sorry if i remember wrongly.

  7. #7
    dowell's Avatar
    dowell is offline Member
    Join Date
    May 2008
    Posts
    6
    Rep Power
    0

    Default

    Quote Originally Posted by rockie12 View Post
    I am trying to run a java program every 10 minutes on my windows PC. If I run the program manually all works fine...

    java myProgramName

    Since windows does not support crontab type functionality, I have installed pycron and it runs my program every ten minutes, but I get a class not found error.

    I have tried

    0,10,20,30,40,50 * * * * javaw myPackage.com.myProgram


    I have added my program to the system environment variable CLASSPATH, but still no success.

    Any thoughts on how I can set up cron on windows to run my java application?

    Thanks in advance for your assistance
    Dean-O

    I suggest that you try using a thread. You can set the thread to sleep for 10 minutes i.e Put the main class in an endless loop and put the thread in that loop.
    Thread.sleep(600000).

    After that you can add its exe jar file to the start-up programs so thats its launched on every log-on or when the computer starts up.

    try it out...

  8. #8
    danielstoner's Avatar
    danielstoner is offline Senior Member
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    191
    Rep Power
    6

    Default

    Windows supports cron like functionality. It is called Task Scheduler. Go to Control Panel/Scheduled Tasks and there you can specify when your program should run. Keep in mind to provide the password for the user your task will impersonate.
    Daniel @ [www.littletutorials.com]
    Language is froth on the surface of thought

Similar Threads

  1. Accessing unix system using java
    By abhishek.sinha in forum AWT / Swing
    Replies: 3
    Last Post: 06-19-2008, 08:05 AM
  2. Filter a file in java (unix cut command equivalent)
    By marcosabel in forum New To Java
    Replies: 0
    Last Post: 02-11-2008, 07:26 PM
  3. Replies: 0
    Last Post: 02-06-2008, 02:07 PM
  4. Running java program with arguments in Unix"
    By gvi in forum Advanced Java
    Replies: 2
    Last Post: 11-08-2007, 07:01 PM
  5. Help with windows in java
    By lenny in forum AWT / Swing
    Replies: 1
    Last Post: 08-07-2007, 06:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •