I have an embedded jetty project that builds a single .jar file that starts up our webapp.
public static void main(String[] args){
final Server server = new Server(threadPool);
//Do config/setup code for servlets/database/contexts/connectors/etc
server.start();
server.dumpStdErr();
server.join();
}
So while this works great to start our server by calling java -jar MyApp.jar I am at a loss for a way to stop it. This is especially annoying when I want to stop the server via our build server.
When we used the Jetty service and deployed a .war file we could do this:
- Build latest .war file via Jenkins
- Stop Jetty service via shell (sudo service jetty stop)
- Overwrite old .war file in /opt/jetty/webapp with new .war file
- Start Jetty service via shell (sudo service jetty start)
I currently have two ideas:
- Create a servlet that calls server.stop() if you have a secret get parameter specified. Use curl on the shell in Jekins to hit this servlet.
- Use something like Apache-Commons daemon wrapper to make my app into a service.
Is there some obvious mechanism I am missing to stop the server?