Scheduling a java program on Windows

Discussion in 'Java' started by Mike, Mar 16, 2005.

  1. Mike

    Mike Guest

    How can I execute a Java program using Windows (XP) Task Scheduler?

    Do I have to place a batch program wrapper on it?
     
    Mike, Mar 16, 2005
    #1
    1. Advertising

  2. Mike

    Malte Guest

    Mike wrote:
    > How can I execute a Java program using Windows (XP) Task Scheduler?
    >
    > Do I have to place a batch program wrapper on it?
    >
    >

    I am running quite a few on a Windows NT server. I schedule cmd files
    that wrap calls to java (java -jar ....)
     
    Malte, Mar 16, 2005
    #2
    1. Advertising

  3. If you have the classpath already set up you can do everything on the
    command line in your shortcut. Otherwise you must use a batch file to set
    environment variables.

    >Subject: Scheduling a java program on Windows
    >Date: Wed, 16 Mar 2005 18:58:18 GMT
    >
    >How can I execute a Java program using Windows (XP) Task Scheduler?
    >
    >Do I have to place a batch program wrapper on it?
     
    David McDivitt, Mar 16, 2005
    #3
  4. Mike

    Mike Guest

    Thanks Malte.

    Could you or some other kind soul please point me to sample code on
    the Web to do the wrapper?

    I'm a Unix type.



    On Wed, 16 Mar 2005 20:25:15 +0100, Malte
    <> wrote:

    >Mike wrote:
    >> How can I execute a Java program using Windows (XP) Task Scheduler?
    >>
    >> Do I have to place a batch program wrapper on it?
    >>
    >>

    >I am running quite a few on a Windows NT server. I schedule cmd files
    >that wrap calls to java (java -jar ....)
     
    Mike, Mar 16, 2005
    #4
  5. Mike

    Malte Guest

    Mike wrote:
    > Thanks Malte.
    >
    > Could you or some other kind soul please point me to sample code on
    > the Web to do the wrapper?
    >
    > I'm a Unix type.
    >


    The below is a windows cmd file (named ldapsync.cmd). What it does isn't
    too interesting, it sucks all entries from Active Directory using LDAP
    calls and copies them into Oracle LDAP. The cmd file could be much
    prettier, but it should get you started. It begins by setting the
    envionment, much as you would do it on unix. It then runs the first
    program, LDAPsync.jar.
    The cmd file then sets up the environment to run the second jar file,
    adg2oidg.jar, then exits. I could have put the commands in two separate
    cmd files, but since they have to run both of them, and in the order
    specified, it was easier to just put them both in the same file.
    Bascially, this is as simple as a shell script on unix. Windows cmd
    files are a bit more flexible these days than they used to be, but can't
    hold a candle to bash, of course.

    As it happens, the example below shows two different ways of calling
    Java from within the file. The first program is called using only
    variables, the second program explicitly sets the classpath.

    If some of it looks weird it may be because I have removed a litte bit
    to protect the innocent (and the customer).

    Lastly, rather than have Java use getResourceAsStream() these two
    programs take their properties files as arguments to main().

    REM ldapsync.cmd

    echo off
    set PATH_TO_LOGFILE=d:\opt\xxx\ldapsync\conf\ldapsync.newproperties1
    set PROGRAM_PATH=d:\opt\xxx\ldapsync
    set JAVA_ARGS=-jar
    set PROGRAM_ARGS=%PATH_TO_LOGFILE%
    set PROGRAM_NAME=%PROGRAM_PATH%\LDAPsync.jar

    java %JAVA_ARGS% %PROGRAM_NAME% %PROGRAM_ARGS%

    set PATH=D:\opt\jdk\bin;%PATH%
    set PROGRAM_PATH=d:\opt\xxx\adg2oidg.jar
    set PATH_TO_LOGFILE=d:\opt\xxx\ldapsync\conf\ADGrp2OIDGrp.properties

    java -jar adg2oidg.jar %D:\opt\xxx\ldapsync\conf\ADGrp2OIDGrp.properties
    -classpath D:\opt\jdk\jdk\jre\lib

    REM exit
     
    Malte, Mar 16, 2005
    #5
  6. Mike

    Lisa Guest

    "Mike" <> wrote in message
    news:...
    > How can I execute a Java program using Windows (XP) Task Scheduler?
    >
    > Do I have to place a batch program wrapper on it?
    >

    The command to execute is "schtasks create"
    there are a lot of options so I suggest that you read
    about it

    start -> help and support
    when the help and support center window opens,
    use the search box to search for "schtasks" and it will explain the whole
    thing.

    HTH
     
    Lisa, Mar 16, 2005
    #6
  7. Thanks to everyone. You've all been a big help.

    Mike



    On Wed, 16 Mar 2005 18:58:18 GMT, (Mike) wrote:

    >How can I execute a Java program using Windows (XP) Task Scheduler?
    >
    >Do I have to place a batch program wrapper on it?
    >
     
    Peter Guitzmyer, Mar 16, 2005
    #7
  8. Mike

    Cram TeXeD Guest

    On Wed, 16 Mar 2005 18:58:18 GMT, < Mike > dit :

    >How can I execute a Java program using Windows (XP) Task Scheduler?
    >
    >Do I have to place a batch program wrapper on it?
    >


    http://javaservice.objectweb.org/ I think it's what you're searching.
    By JOnas fathers.

    8:0) Cram TeXeD
    --
    "On ne peut pas ne pas communiquer"
    axiome n°1 de Paul Watzlawick
    <http://texed75.free.fr>
     
    Cram TeXeD, Mar 17, 2005
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rey
    Replies:
    4
    Views:
    11,065
    Roedy Green
    Dec 12, 2003
  2. Kristian Bisgaard Lassen

    Re: Java scheduling/calendaring

    Kristian Bisgaard Lassen, Jan 12, 2004, in forum: Java
    Replies:
    2
    Views:
    339
    Chris Berg
    Feb 19, 2004
  3. Replies:
    1
    Views:
    543
    Andrew Thompson
    Oct 31, 2005
  4. Replies:
    1
    Views:
    3,241
    Daniel Dyer
    Mar 12, 2007
  5. raj
    Replies:
    6
    Views:
    1,485
    yemenjava
    Feb 10, 2009
Loading...

Share This Page