2

How to run Maven as soon as my server boots? Is it OK to have a script executed using cron once the server run? or is this a bad practice? I am using Jetty and Resteasy and running them on Maven to start my webserver.

What is the best solution for when my server starts, Maven automatically starts? The command is use is:

mvn jetty:run -e

EDIT: I am using Amazon EC2 to launch an instance and I would like to have the maven build to run as soon as an instance is launched. Maven builds and runs Resteasy, Jetty and a bunch of other dependencies that are stated in the pom.xml file.

Reza
  • 684
  • 1
  • 10
  • 22
  • Reza, what do you want maven to do for you, after your server starts? jetty:run will start jetty running on port 8080. check plugin page for more info: http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin – mhshams Nov 25 '12 at 06:28
  • Would is be simpler to use something like Jenkins to run your Maven builds, and invoke the Jetty job on startup using the Jenkins API? – Mark O'Connor Nov 25 '12 at 15:28
  • Thanks @mohammadshamsi Please take a look at the EDIT on the questions. Technically when I use Maven and run mvn jetty:run -e the server starts with all configuration on my shell. But I want to make this as a daemon or run the mvn jetty:run -e at startup so I wouldn't have to manualy connect to the server and run the command. – Reza Nov 25 '12 at 20:35
  • @Reza Consider Jenkins (Hudson) to build and run your maven builds, if you need to build and run them quite often. – mhshams Nov 26 '12 at 02:02

2 Answers2

0

You can use your OS specific init scripts approach. A very good answer for Ubuntu OS can be found here.

Community
  • 1
  • 1
Mikhail Tsaplin
  • 642
  • 1
  • 9
  • 21
0

Usually, you use Maven as a build tool, not a deployment tool.

What are you trying to accomplish? If you just want to boot Jetty, it comes with its own init scripts which will start it on boot if you enable them.

Unless there is a convincing reason to use Maven for this, I would have your Maven build process create an "executable unit" such as an executable JAR, a WAR, etc. and then boot that at startup instead.

Steven Schlansker
  • 37,580
  • 14
  • 81
  • 100
  • The reason I am using Maven for deployment is basically: We are deploying a large set of machines on Amazon and the build (code) changes quite often (hourly basis). The concept is that we want to evolute the code as we run on the cloud. – Reza Nov 25 '12 at 22:57
  • I would suggest using Jenkins or some similar tool to do builds, distribute those, and run the completed builds. Much easier to track exactly what is going on. – Steven Schlansker Nov 26 '12 at 02:57