Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Releasing from development into production in maven

Tags:

java

maven-2

I'm confused about the use of maven in development and production environments - I'm sure it's something simple that I'm missing. Grateful for any help..

I set up maven inside eclipse on my local machine and wrote some software. I really like how it's made things like including dependent jars very easy.

So that's my development environment. But now I want to release the project to production on a remote server. I've searched the documentation, but I can't figure out how it's supposed to work or what the maven best practice is.. Are you supposed to:

a) Also be running maven on your production environment, and upload all your files to your production environment and rebuild your project there? (Something in me baulks at the idea of rebuilding 'released' code on the production server, so I'm fairly sure this isn't right..)

b) use mvn:package to create your jar file and then copy that up to production? (But then what of all those nice dependencies? Isn't there a danger that your tested code is now going to be running against different versions of the dependent jars in the production environment, possibly breaking your code? Or missing a jar..?)

c) Something else that I'm not figuring out..

Thanks in advance for any help!

like image 339
Jeremy Avatar asked May 07 '10 18:05

Jeremy


People also ask

What does mvn release do?

mvn release:perform This is the command which actually does the release by downloading the tagged version from SCM e.g. SVN or CVS or Git. We usually call this command after release:prepare, which creates the tag in SCM but you can also release any specified tag created previously.

What is groupId and artifactId in Maven?

The groupId is a parameter indicating the group or individual that created a project, which is often a reversed company domain name. The artifactId is the base package name used in the project, and we use the standard archetype.


2 Answers

  • You're supposed to have your code under version control (and you never "upload" files to another machine, you "download" them from the Version Control System if required).

  • You're supposed to package your code in a format (a WAR, an EAR, another kind of bundle) that can be deployed on the production environment for execution. Such bundles typically include the dependencies. To build more complex bundles, the Maven Assembly Plugin can help.

  • Maven generated artifacts (JARs, WARs, whatever) should be shared via a remote repository (and thus deployed - I mean mvn deploy here - to this remote repository). A remote repository can be a simple file system served via a web server or a more advanced solution like Nexus.

  • Development is usually done using SNAPSHOT dependencies (e.g. 1.0-SNAPSHOT). At release time, you're supposed to change the version into a "fixed" version (e.g. 1.0) and some other bits from your pom.xml, run the build to check that everything is ok, commit the modified pom.xml, create a tag in the VCS, promote the versions to a new SNAPSHOT (e.g. 1.1-SNAPSHOT) in the pom.xml, commit the new pom.xml in the VCS. The entire process require some work but this can be automated using the Maven Release Plugin.

  • On the production environment, get the artifacts to be deployed from the remote repository and deploy them (some projects automate the deployment to the production server using Maven but that's another story).

Of course, there are variations around this (deployment to production is most of time company specific) but the general idea is there.

like image 184
Pascal Thivent Avatar answered Sep 22 '22 01:09

Pascal Thivent


You need to look into the Maven Assembly Plugin and the Maven Release Plugin.

like image 42
Jason Nichols Avatar answered Sep 20 '22 01:09

Jason Nichols