I am a newbie when it comes to Java and Jetty app deployment. I use the default settings for setting up my jetty serve and ran java -jar start.jar
on my terminal window. The server runs as expected, but when I close my terminal it stops. Is this normal? I used XAMPP before and there you can close the terminal without any problem. How do I overcome this problem, everybody needs to shut down there personal computer once in a while.
I'm using a mac btw.
It sounds like you're using ssh or something like that to start Jetty on a remote Linux/Unix server.
So, you can use nohup java -jar start.jar &
- nohup
will prevent your process from being stopped by the usual Unix "hangup" signal (ref) when you log out, and the &
will put jetty as a background process so you can type exit
or whatever to log out.
If you want to be able to re-attach to the Jetty terminal, I'd recommend reading up on GNU screen.
If you want to stop jetty gracefully again, I'd really recommend using it as a service, or using screen
to avoid losing the terminal. But if it's too late for that you can find the PID in the output of jps -l
and then call kill $PID
.
How to kill process:
1) java style
when start jetty :
java -DSTOP.PORT=8077 -DSTOP.KEY=secret_key_only_admin_know -jar start.jar
for stop:
java -DSTOP.PORT=8077 -DSTOP.KEY=secret_key_only_admin_know -jar start.jar -stop
P.S. ports can be any - but they must be the same for start and kill commands :)
2) linux style
kill process by PID
You can set up jetty to run as a service... here's the instruction for linux and windows. This way, you don't need to worry about launching jetty everytime through the terminal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With