Run a Play framework application as a Windows Service with YAJSW kindly explains how to run a Play! 1.x applications as a Windows Service, but unfortunately it does not work for Play! 2.0 application. I could not find the good solution for Play! 2.0 applications on the internet, so I note my solution. Hope it would be someone’s help.
- Build your application for deploy.
-
Deploy your application by using the stage task.
$ play clean compile stage
- Download Yet Another Java Service Wrapper (YAJSW).
- Unzip YAJSW to
%app%
(where%app%
is the path to your application) and rename the directory towrapper
. - Create 2 directories:
%app%\log
(for log files) and%app%\temp
(for temporary files). -
Edit
%app%\wrapper\conf\wrapper.conf
.Example (please change
PATH_TO_YOUR_APP
to%app%
):# Example YAJSW configuration to run Play! application as service wrapper.working.dir=PATH_TO_YOUR_APP wrapper.java.app.mainclass = play.core.server.NettyServer wrapper.java.classpath.1 = ${wrapper.working.dir}/conf/* wrapper.java.classpath.2 = ${wrapper.working.dir}/target/staged/* wrapper.java.additional.1 = -Djava.io.tmpdir=temp wrapper.logfile=${wrapper.working.dir}/logs/wrapper.log wrapper.console.title = Play! service test wrapper.ntservice.name = Play! service test wrapper.ntservice.displayname = Play! service test wrapper.ntservice.description = Running a Play! app as windows service
- Execute
%app%\wrapper\bat\runConsole.bat
and confirm your application starts. - Install the service. Execute
%app%\wrapper\bat\installService.bat
. The newPlay! service test
service should be created. - Start the service via
Service
inComputer Management
.
コメント
There is a good possibility to run the PLAY! framework as windows service with JNA. I deployed several java implementations in this way on windows server 2008 SP2 successfully being monitored by PRTG (which has not intervened in a period of 6 months until now). If we decide to use PLAY! in our web stack i will write an article about it and publish it here.
Thanks, that was exceedingly helpful! I was already gearing up for a long struggle getting my application to run as a service with Apache procrun, but YAJSW is a joy to use, and with your example it was a breeze to get going.
Help me to get a windows service that can be started/stopped and even restarted successfully. Thanks!
Thank you. This is really great information and easy to follow.
application.conf fails to load because setting cp to
wrapper.java.classpath.2 = ${wrapper.working.dir}/target/staged/*
tries to load it from jars inside conf directory, but conf directory contains conf files themselves.
Setting
wrapper.java.classpath.2 = ${wrapper.working.dir}/target/staged
solves the problem.Thank you for the posting, this really helped a lot. I finally managed to get the service started, it took me a whole day though, wish I had seen this earlier.