Pregunta

Hi all so i have wrote a program in java (using eclipse) and exported single class program to a .jar file. This program also starts a batch file. When i double-click the .jar file the jar runs perfectly and starts the batch file.

But what i want to do is for the .jar file to run every weekly, so with windows scheduler i created a task with the action being the .jar file. This did not work. I then read somewhere that windows scheduler dose not like .jar so i thought of making a second batch file(start.bat) to start the .jar which would then start the first batch file.

The command in my start.bat is

java -jar myJar.jar

When i double click the start.bat file everything works. But when i set the windows scheduler to start this task i get the following error message for a cmd window

Error: Unable to access jarfile myJar.jar

This really has me stumped as all the files are in the same directory. Any help would be seriously be appreciated, thanks.

¿Fue útil?

Solución

Obviously this comment was the answer:

use the full path of myJar.jar instead of a relative path - the running directory of the windows scheduler is C:\Windows\System32 and your jar-file is probably not in this directory.

Otros consejos

Task Scheduler cannot run .jar directly you need to run it via command prompt. Because the task scheduler runs the .bat via cmd its default executing location i.e, C:/windows/system32 we need to change the path. While scheduling task in scheduler call TaskName.bat as action. SO,

Create a batch file "TaskName.bat" In TaskName.bat Enter the Following

@echo off

cd "Path to the jar file Example C:\MyFolder"

java -jar Nameofthejar.jar

pause

If you follow the following steps you will not get any issues.

Step 0 : Setup

Add app.schedule.externally_managed=true in application.properties

Step 1: Create a New Task

Click Create

Provide details

Configure for Windows 10 is important

Step 2: Trigger Details

Step 3: Action Details

Step 4: Actions

Make sure all the checkboxes are unchecked as shown below, this is important

Step 5: View Task Details

Refer this and this for more details

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top