Tuesday, October 30, 2012

Play 2 Framework as a Windows Service

I wanted to run Play2 as a Windows Service, but had problems getting it to work with the usual methods (SC.exe) (See http://www.herikstad.net/2012/10/run-as-windows-service.html for others).

Ended up using RunAsSvc from PirmaSoft. Here is how:


1. In command prompt. Go to your project folder. Run play dist. This will create a ZIP file in the dist folder of your project.
3. Unzip the ZIP file in a location of your choice-
4. Download RunAsSvc from http://www.pirmasoft.de/runassvc.php and unzip it in a location of your choice.
5. Run RunAsSvc.exe as an Administrator
 5.1 Choose a Name for your service
 5.2 Choose a Description for your service
 5.3 In "Path to executable" browse to your Java/bin folder (e.g. C:\Program Files\Java\jre7\bin) and choose java.exe
 5.4 In "Parameters" Enter: -Dhttp.port=80 -cp "./lib/*;" play.core.server.NettyServer . (you only need the -Dhttp.port=80 flag if you want to set the port to something other than 9000).
 5.5 Set the working directory to the locations where you unzipped the project ZIP file.
 5.6 Press OK and check that you now can find your service in the Service panel (services.msc) and that you can open your webpage in your browser.

To delete the service, go to "Add/Remove Programs" and find PirmaSoft RunAsSvc - <your service name> and select uninstall.

If the service won't run, check that there is no RUNNING_PID file in the folder where you unzipped the ZIP file.

To see the process in Task Manager: Select "Show processes from all users", it will be a java.exe running as SYSTEM.

Sources:  https://groups.google.com/forum/?fromgroups=#!topic/play-framework/xykhfyVu_Y0,
http://stackoverflow.com/questions/9689793/cant-execute-jar-file-no-main-manifest-attribute,
http://stackoverflow.com/questions/10894615/play-framework-bat-windows-java-process,
http://stackoverflow.com/questions/9941689/how-to-change-http-port-that-play2-is-listening-on

1 comment: