Maven jetty plugin - delay when starting in background mode

坚强是说给别人听的谎言 提交于 2019-12-04 12:55:46

I get so tired of watching people abuse nohup. Here's how real daemonization routines work:

  1. Create a child process.
  2. Launch daemon as a child of that child process.
  3. Exit the first process.

A simple way to emulate this using sh is as follows.

sh -c "mvn jetty:run &"

Observe...

scott@optimusprime:~/code/leapfrog/lasso> sh -c "mvn jetty:run &"
scott@optimusprime:~/code/leapfrog/lasso> ps aux | grep jetty:run
scott    26165 45.5  5.8 813556 235764 pts/9   Sl   15:23   0:06 /usr/lib/jvm/java-6-sun//bin/java -Xmx512M -classpath /home/scott/opt/apache-maven-2.2.1//boot/classworlds-1.1.jar -Dclassworlds.conf=/home/scott/opt/apache-maven-2.2.1//bin/m2.conf -Dmaven.home=/home/scott/opt/apache-maven-2.2.1/ org.codehaus.classworlds.Launcher "jetty:run"
scott@optimusprime:~/code/leapfrog/lasso> exit

If I check my process list from a separate terminal, or later, the program is still running.

However I have to ask, why do this instead of just install your web application in a local application server, and start it? Hopefully you aren't managing your real environments using apache maven.

I would run it in the foreground, and trigger a thread dump (Ctrl+Break), and see what it's doing by inspecting each thread stack trace. Without any further information I can't offer any more advice.

I suggest you try using screen. Might be overkill for such a simple task, but you can wrap it in a shell script.

Using maven is very convenient to download, install and start an application. Among many other benefits, maven offers developers the ability to manage the version of Jetty. Using the advice provided here I think maven fits the bill as a production initiation mechanism.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!