2

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.

Blankman
  • 259,732
  • 324
  • 769
  • 1,199
  • Consider using a more standardlized production folder structure talked in this [Q&A](http://stackoverflow.com/questions/10151458/building-complete-application-folder-with-maven/10152209#10152209). – yorkw Apr 17 '12 at 21:55

3 Answers3

5

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).

Puce
  • 37,247
  • 13
  • 80
  • 152
2

@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.

Gareth Davis
  • 27,701
  • 12
  • 73
  • 106
  • Thanks. Is it possible for me to cherry pick a file from my other module and add it to my lib folder? – Blankman Apr 17 '12 at 20:35
  • 1
    not really, strictly speaking you should only make reference to the binary output of a maven project, i.e. the jar file. You can get hold of those using the dependency plugin. – Gareth Davis Apr 17 '12 at 20:37
  • 1
    @Blankman You can use the unpack-dependencies goal of the maven-dependency-plugin to extract resources from an artifact. Then you can include it in your assembly. – Puce Apr 17 '12 at 21:44
  • wait, actually my /resources folder for some reason is being included in my .jar, and it has development folder paths (there is a properties file in there), how can I exclude the /resources folder? please help! – Blankman Apr 17 '12 at 21:54
  • i only want the resources to be excluded during the mvn assembly build. – Blankman Apr 17 '12 at 21:58
  • Resource files in src/main/resources are suppose to be packaged in the jar. If you need some resources simply for testings, consider putting them in src/test/resources so that those are available while testing, but are not packaged into the production jar. – Kalpak Gadre Apr 19 '12 at 17:54
1

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.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235