How to install a java application as a windows service.

At work we had a java application that was written for us. The application needed to run as a windows service so that it would run on the server without the need for a user to log in. It took me awhile to figure it out, as there was not one spot with all the information I needed. Here’s how I did it, your mileage may vary!

This was compiled with references from MS using the Windows Server 2003 Resource Kit Tools, you can use the resource kit appropriate to your server install. The only files needed from the resource kit are the instsrv.exe and the srvany.exe files. These can be found on the internet, but for a corporate server install I thought it was best to download the kit from Microsoft.

Now to the steps:

  1. Use instsrv.exe to install srvany.exe as the service, from the command line: <path>\<to>\instsrv.exe <application_name> <path>\<to>\srvany.exe.
  2. Run regedit and Find: My Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\ Services\<application_name>
  3. Select the <application_name> and select “Edit..”, “New…”, “Key“.
  4. Name the key Parameters.
  5. Select the Parameters key that you have created, and select “Edit…”, “New…“, “String Value“.
  6. The Name should be Application.
  7. Double click the name to open a dialog in which you can enter the value <path>\<to>\<jre>\javaw.exe.
  8. Select “Edit…”, “New…“, “String Value
  9. The Name should be AppDirectory.
  10. Double click the name to open a dialog in which you can enter the value <path>\<to>\<java class files>.
  11. Select “Edit…“, “New…“, “String Value“.
  12. The Name should be AppParameters.
  13. Double click the name to open a dialog in which you can enter the value -Xrs <application_name>

IMPORTANT! : the -Xrs must be in the AppParamenter name.

Notes: Ensure the service is set to “Log on” as a Local System Account, and the “Interact with desktop” is unchecked.

This is how I did it. The most important part was using the -Xrs value. It would not work at all until that value was set.

Comments or Questions?

Advertisements

One thought on “How to install a java application as a windows service.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s