Blankman
Blankman

Reputation: 267040

Using maven to produce production ready output

I have a muti-module maven project, and I created a new module that depends on 3 other modules. (I already have a web app maven module that produces a .war file, now I need this)

This module's output is a .jar, and it has a few resources also which are:

  1. spring context xml file
  2. properties file

Now I want to produce a production ready folder so I can upload it to my server. I am hoping maven can do this for me.

I need the following layout:

myjar.jar
/libs/  (the 3 other maven modules that are dependancies)
/resources

Also, there are some generic dependancies that my parent pom.xml have like slf4j/log4j/ that I also need to package.

It would be cool if I could add a switch to mvn that will produce this like:

mvn clean install production

I plan on running this on my server via the command line.

Upvotes: 2

Views: 6664

Answers (3)

khmarbaise
khmarbaise

Reputation: 97437

The intention of Maven is building not deployment in the sense to production. For this purpose i would recommend things like Chef or Puppet. From a technial point of view it's of course possible to handle such things via Maven. What also possible to build on CI solution like Jenkins. Furthermore it's possible to run a script from Jenkins to do the deployment on production.

Upvotes: 1

Gareth Davis
Gareth Davis

Reputation: 28059

@puce is right in that you may be best to use the Assembly Plugin. What you can't do easily is add another lifecycle 'production' to maven. If you have time you could write a plugin to do this, but you might be better off using a profile called 'production' or 'prod-deploy' to enable the coping into place on the server.

mvn clean install -Pprod-deploy

One thing to remember with maven is that it is very good at building projects in using it's conventions, but it is pretty bad at actually script things to happen out side of the build lifecycle.

I have on several occasions used external scripting tools such as ant/python/bash and groovy to first run the build using mvn then to script the deployment in a more natural language.

Upvotes: 2

Puce
Puce

Reputation: 38132

I think what you are looking for is a Maven Assembly:

https://maven.apache.org/plugins/maven-assembly-plugin/

You can use profiles to disable the generation of the assembly by default (can speed up the development process).

Upvotes: 5

Related Questions