How can I specify the outputDirectory only for packaging a jar?
http://maven.apache.org/plugins/maven-jar-plugin/jar-mojo.html this shows all parameters, but how can I set them in the commandline or pom.xml?
How can I specify the outputDirectory only for packaging a jar?
http://maven.apache.org/plugins/maven-jar-plugin/jar-mojo.html this shows all parameters, but how can I set them in the commandline or pom.xml?
Parameter Expressions
About command line usage:
The parameter documentation specifies that the parameter is initialized to the value of the property
${project.build.directory}
(which is the property referring to the target folder)Here's what this means:
Reference:
Configuring ${project.build.directory}
However,
${project.build.directory}
is not a system property, it's a property of the Project'sBuild
object.You can't set maven's internal properties directly on the command line, but you can get there with a little trick by adding placeholders in your pom.xml:
Now, the output directory is set via the property from the command line (using
-Ddir=somedirectory
). Downside: now you always have to use the-Ddir
parameter on the command line.Using Profiles
But there's help here, too. Just use a profile when you want to configure the directory:
Now you can either do
or plain old
Configuring the Jar Plugin
Now if you just want to change the jar outputDirectory from the command line without redirecting everything from target, we'll modify the profile to configure the plugin from a command line property:
The usage is identical to above:
Thanks @Sean Patrick Floyd for the excellent explanation.
Instead of creating a profile and using
mvn
always by-P
switch, I'd like to use another way that making a default value of property ${dir}.Just define
${dir}
's default value as${project.build.directory}
and same as @Sean Patrick Floyd, set outputDirectory.
Now you can either do
or plain old
If you wish copy dependency jars as well to a target folder, use maven-dependency-plugin.
on command line
and in pom.xml