-2

This seems like such a basic thing..kill app & restart it..

I have this batch file configure to run daily through windows task scheduler:

@ECHO OFF

::Daily reboot to limit ram usage

taskkill /F /IM javaw.exe

::
:: start app again
::

start app.jar

The script is run each day successfully according to windows but it is only closing the program not starting it again. When I double click my .bat file it works just fine..

What am I missing?

TylerH
  • 20,799
  • 66
  • 75
  • 101
  • 2
    If you do not know how to start a jar file, then you should not be posting a question here until you've researched and attempted it first. Based upon your code, I'd expect something similar to, `Start "" "C:\PathTo\bin\javaw.exe" -jar "P:\athTo\app.jar"`. The important thing to remember is that many scheduled tasks are run with `C:\Windows\System32` as the currect directory. That means without providing full paths the script is looking for everything in a different directory. You could of course simply begin your script with `@CD /D "%~dp0"` to keep everything relative to the script itself. – Compo Sep 20 '19 at 10:09

2 Answers2

0

First make sure you have configured environment variable for running java.exe . If not, refer this .

Secondly, always use complete path to start/kill your jar execution.

The command to run your application is:

java -jar app.jar
Gerhard
  • 22,678
  • 7
  • 27
  • 43
AMOGH G
  • 15
  • 6
0

Well I'm in my first year of bachelor only using BlueJ so far to learn java so I apologize. Happy that I now know the task run from c:\win\sys32. I could see the logs from the java app there not finding the libraries. so the @CD /D "%~dp0" I'll try to remember for sure. Thx final code:

@CD /D "%~dp0" 
::Daily reboot to limit ram usage

taskkill /F /IM javaw.exe

::
:: start app again
::

start java -jar d:\path\to\app.jar

full path to javaw.exe was not needed, only diff when running the app with task scheduler is that the last line in log should be "added to SystemTray" making the app visible. Now it is running hidden, which is ok for it's use but I'll try to figure out on my own why.

(just "start app.jar" is also working just fine btw with the @CD /D "%~dp0" on top.)

thx,