0

i need to execute a batch file as windows service.

For that i had created a batch file. In this batch file i just add the below code to run a jar file.

java -jar myTest.jar

When i double click on the batch file..no problem .its working fine. It executes the jar file (a java application).

But the same batch file when i used in a windows service on a windows server, its not working.? Its just getting blinked to show the command window and gets closed. None of my code portion inside the jar file gets executed.

Another thing is i had successfully checked this from another windows server. Its working fine there.

Why this strange issue..??Can anyone help me out to solve the issue..

TKV
  • 2,533
  • 11
  • 43
  • 56

1 Answers1

0

The service is not executed in the same environment as when you run the batch from an interactive Windows session. Make shure in the .bat file that change into the correct (working) directory, even with absolut path (cd \users\my\java\service), and maybe specify the full path to the java.exe. The other server do you mention could have a totally diferent setup of the environment, installed software, etc.

C:
cd \users\my\java\service
"\program files\java\jre\bin\java" -jar test.jar
PeterMmm
  • 24,152
  • 13
  • 73
  • 111