Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Fanhua Zeng
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem solved!


 
Maneesh Godbole
Saloon Keeper
Posts: 10974
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done!
Perhaps you would like to share the solution for the benefit of future users, who have a similar problem.
 
Fanhua Zeng
Greenhorn
Posts: 8
  • 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
lr Kiko
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch Frank Goss
 
Mary Shell
Greenhorn
Posts: 17
C++ Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So simple, yet so elusive!
Thanks so much.
It solved some angst for my customer.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic