I’m working on a project that used ant. I had a target dist that would basically do jar first, and then install the application into a directory.
This means, it would create directories like bin/, lib/ and config/ in the installation directory, and then copy the relevant files into each of these directories.
My question is two-fold:
- Is there any maven goal that does this kind of thing?
- If not, I want to do
maven distand make this happen. How would you suggest I accomplish this using Maven? - If I can’t have my own “target” (like dist), then what would be the best way?
Bottom line: I want to do all this, but don’t want to alter the behavior of the default “targets” like compile and package etc.
Thanks,
jrh
PS: I’m using maven version 2.2.21
I don’t know what would go in
config, butlibandbinis easy.To copy all dependencies to a folder just do this:
To output your jar to a bin folder do this (reference page):
Ah, there are additional requirements:
In this case I’d use a profile to turn this on:
Now you would do
mvn clean package -Pdistto get your dist directory and if you don’t add the profile, you get default behaviour.Basically, things work differently in maven from the way they do in ant. There are no targets, there are only lifecycle phases and plugin goals.
You can either execute a lifecycle phase, which will call all maven plugin goals that are bound to all phases up to this one (e.g. if you do
mvn compile, the following phases will be executed:validate,initialize,generate-sources,process-sources,generate-resources,process-resources,compile). But there is no (easy) way to define a lifecycle phase nameddist.Or you can execute a specific plugin goal (you can actually execute multiple phases and / or plugin goals). E.g. you could write your own dist plugin and call it using
mvn dist:dist, but I wouldn’t recommend that because you are using existing functionality and the profile solution should be a pretty good fit.