aspose file tools*
The moose likes General Computing and the fly likes How do I schedule a .jar file using windows 7 task scheduler Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » General Computing
Bookmark "How do I schedule a .jar file using windows 7 task scheduler " Watch "How do I schedule a .jar file using windows 7 task scheduler " New topic
Author

How do I schedule a .jar file using windows 7 task scheduler

Fanhua Zeng
Greenhorn

Joined: Feb 26, 2008
Posts: 8
Hi.

I have an executable jar file and am trying to create a scheduled task using windows 7 Task Scheduler.
It runs fine as a .jar file when I double click it. But when I tell task scheduler to run it, it comes up with nothing.

Here is how I create tasks in the scheduler:

Program/script: "C:\Program Files\Java\jre7\bin\javaw.exe"
Arguments: -jar C:\Users\admin\Desktop\TestTask.jar

I have also tried using batch file but it doesn't work either, here is my script in bat file.

start "" "C:\Program Files\Java\jre7\bin\javaw.exe" -jar C:\Users\admin\Desktop\TestTask.jar

It also works fine when I double click the bat file.

How does task scheduler not run .jar files? Or I did something wrong?

My code:




Can someone please help?


Regards,
Fanhua





Fanhua Zeng
Greenhorn

Joined: Feb 26, 2008
Posts: 8
Problem solved!


Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10535
    
    9

Well done!
Perhaps you would like to share the solution for the benefit of future users, who have a similar problem.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Fanhua Zeng
Greenhorn

Joined: Feb 26, 2008
Posts: 8
When we call a .jar file using task scheduler, it runs fine if we don’t use file IO.
However, in my case, I was trying to save a file, I have to specify the ‘Start in (optional)’ in the task scheduler so that the task scheduler knows where to store the file.

The setting is:
Program/script: "C:\Program Files\Java\jre7\bin\javaw.exe"
Arguments: -jar C:\Users\admin\Desktop\TestTask.jar
Start in (optional): C:\Users\admin\Desktop ---- added

Cheers,
Fanhua
ramya Lakshmanan
Greenhorn

Joined: Mar 18, 2009
Posts: 4
I have a similar problem but in windows server 2003..
I would like to schedule a jar file to run which uses IO.
Can someone help?
Fanhua Zeng
Greenhorn

Joined: Feb 26, 2008
Posts: 8
ramya Lakshmanan wrote:I have a similar problem but in windows server 2003..
I would like to schedule a jar file to run which uses IO.
Can someone help?


Did you specify where your *.jar is?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Fanhua Zeng wrote:However, in my case, I was trying to save a file, I have to specify the ‘Start in (optional)’ in the task scheduler so that the task scheduler knows where to store the file.


It's not the task scheduler. It's so that the JVM's "current directory" is the one you want it to be.

Alternatively, rather than specifying "start in", you could use a full path to the file, rather than a relative one. You could either hardcode that path (not generally a good idea) or provide it as an argument to the command you set up in Task Scheduler. I would prefer this over the "Start In" option because Java programs generally don't need to know or care what the JVM's current directory is.
Fanhua Zeng
Greenhorn

Joined: Feb 26, 2008
Posts: 8
Jeff Verdegan wrote:
Fanhua Zeng wrote:However, in my case, I was trying to save a file, I have to specify the ‘Start in (optional)’ in the task scheduler so that the task scheduler knows where to store the file.


It's not the task scheduler. It's so that the JVM's "current directory" is the one you want it to be.

Alternatively, rather than specifying "start in", you could use a full path to the file, rather than a relative one. You could either hardcode that path (not generally a good idea) or provide it as an argument to the command you set up in Task Scheduler. I would prefer this over the "Start In" option because Java programs generally don't need to know or care what the JVM's current directory is.


I would say it depends on what problem you are deal with. In my case, my *.jar file has a separated configuration file (not in the jar). You probably would want to use “Start in (optional)”. The reason we have a separated configuration file is that non-java programmer people can just edit the file if something changes instead of coming to you and asking you to modify the java code.
Frank Goss
Greenhorn

Joined: Apr 27, 2012
Posts: 1
Thanks for posting the solution! I was having the same problem until I realized I was storing a file on the windows system. The "Start in " parameter was just what I needed.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Welcome to the Ranch Frank Goss
Mary Shell
Greenhorn

Joined: Jan 15, 2003
Posts: 15

So simple, yet so elusive!
Thanks so much.
It solved some angst for my customer.


Thanks,
Mary
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I schedule a .jar file using windows 7 task scheduler