How to run Maven on startup as a daemon or standalone - java

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.

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

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.

Related

Teamcity - How to run spring boot jar on server after Build and Deploy?

I have a Rest API based on Spring boot, embedded with jetty. Normally I start it with java -Dloader.path=blablabla -jar blablabla.jar. I've configured a teamcity Build step to look for new check-ins to the git repo, pull and build (maven) the project, generate artifacts..
Further, I've added a Deploy step which has dependency on Build step (successful completion and artifact dependency).. Here, I use powershell to push the artifacts to the server on which i want the rest service to run.
A few questions:
1) Powershell - Is it the right way to publish files to the server from teamcity?
2) How do i get the teamcity to actually start my spring boot app? Some sort of a remote command execution?
Note: Both teamcity server and the app server are Windows.
Solved it myself:
1) Yes, powershell does the trick pretty neatly.
2) Got it to work with a combination of [WMICLASS] 's create() and Start-Process. Check my answer here.
Cheers!

Run Automation Scripts after Deployment on Tomcat Server using Jenkins

I've deployed a servlet based web application(War file) in Tomcat server using Jankins and Maven. Now I want to run some selenium automation scripts on same application, Can it be achieved by Jenkins.
Its like Deploy web application on Sever and once deployment is successful run automation scripts using jenkins..
Please Help..
Two possible ways :
1) Add post build step to your current task and run the scripts there.
2) Add another task ex. "app-automation-scripts" that runs every time that your current task is builded correctly.
Yep,
you can add maven plugin to jenkins, (installed by default most of times)
then declare your project as war in pom.xml
then add a post processing "maven" to your maven build config and configure it with options "war:war"
-- options you can add for a maven build is: clean install build and etc. war option is for creating war files.
Or:
simply run a bash command using your jenkins build configuration.
Former needs installation of maven plug-in and configuring it,
Later needs configuring your maven to be run on the jenkins server by user named "jenkins".

Deploy Java EE project to WebSphere 7 WITHOUT Eclipse

I am getting tired of all the bugs in eclipse and m2eclipse, and would like to build with maven using the command prompt, plus afterwards start the server, and deploy the application to the server and publish it using the command prompt. Normally I do that within eclipse servers tab.
If I make a change to the code, then I should just rebuild with maven and republish.
I am aware that you can deploy an EAR in Wepshere admin web console, but it is not ear I am thinking of, at least I don't think so. I want to be able for example, once application is deployed, jRebel should be able to reload the clases in the jvm, but I believe the ear file is standalone so that wouldn't work.
So,
How can I start the server from the command prompt, plus deploy a project and publish it ?
Thanks!
You can automate the build so that it deploys the app as well, at least with Maven. Have a look at this post: Maven 2 and WebSphere:
WebSphere has (had?) a Rapid Deploy feature that you can use for "hot" deployments. Essentially it fired up a headless Eclipse for this, but it was much faster than a full EAR build and just as dynamic as going through WTP.
At the time, we had an Ant task that we used to copy the files over to the WRD directory. I'm not sure how that would work with Maven, but I imagine one could rig up something.

How to run a maven Java app on a server

I have a standalone application which I have deployed using the Maven release plugin.
I now need to run it on the remote server...
Would you recommend using the mvn exec plugin?
Otherwise whats the best way of running the app (i.e. working out the correct classpath etc).
Thxs
You can use the Maven Assembly Plugin with jar-with-dependencies descriptor (it's one of default descriptors). It should include all dependencies, allowing you to easily run the jar on the server.
Either the exec plugin, or use the dependencies plugin (or any of the jarjar-/onejar-type utilities) to create an all-in-one jar and just distribute that.

maven deploy goal failing

I am using eclipse with maven2 plugin.
When doing a Run-As -> build with a goal of 'deploy' I am getting this error:
Error message:org.codehaus.plexus.component.configurator.ComponentConfigurationException: Class 'org.apache.maven.artifact.repository.ArtifactRepository' cannot be instantiated
I'm not sure I even need to do a 'deploy', I have another build that does a 'compile' goal, and from what I have learned doing a Run-As -> Run on Server (tomcat) is enough to deploy my application locally to tomcat.
Do I need run this build 'deploy' goal to run locally, should I just delete it and use 'run on server'?
Running mvn deploy won't "deploy your application on Tomcat", deploy is something different here, deploy is a phase done in an integration or release environment and copies the final package to the remote repository for sharing with other developers and projects.
In other words, unless you are dealing with a remote repository to distribute your application (and this requires to configure a valid <distributionManagement/> section in your POM), just forget about deploy for now, this is not what you think it is :)
So, to run your application and "deploy it on Tomcat" from Eclipse, use Run As > Run on Server. If you want to run it from outside Eclipse, you can use mvn tomcat:run but this isn't really appropriate here (this goal is an handy way to run a webapp without importing it in a IDE). And if really you want to deploy your application on Tomcat from the command line, the Maven Tomcat plugin supports many methods for Deployment. But again, I don't think that this is what you're looking for for now.

Categories

Resources