Scheduling a java program on Windows

M

Mike

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

Do I have to place a batch program wrapper on it?
 
M

Malte

Mike said:
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 ....)
 
D

David McDivitt

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.
 
M

Mike

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.
 
M

Malte

Mike said:
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
 
L

Lisa

Mike said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top