• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

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

 
Greenhorn
Posts: 8
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Problem solved!


 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Likes 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 80665
478
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch Frank Goss
 
Greenhorn
Posts: 17
Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So simple, yet so elusive!
Thanks so much.
It solved some angst for my customer.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it worked for me as well. thanks
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic