Hi, I am very new to Maven and would like to see an example of how one uses the maven jar plugin. I already visited here but did not find any examples. On the documentation page, there were some parameters listed for this goal but what I was looking for is how one places them in the 'goal' or 'executions' tag. Thanks.
You usually don't use the jar plugin. If you set the packaging to jar, the goal jar:jar gets executed automatically.
If you want to configure the jar plugin, do it like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<excludes>
<exclude>**/*.xml</exclude>
</excludes>
</configuration>
</plugin>
(Example: exclude all xml files from the jar)
There is no need to add any goal or execution blocks, a global configuration block is valid for all executions.
Reference:
I am very new to Maven and would like to see an example of how one uses the maven jar plugin. I already visited here but did not find any examples.
All maven plugins have usually a Usage page, so does the Maven JAR Plugin. But as pointed out by seanizer, it's unusual to invoke the Maven JAR Plugin directly, you don't really "use it directly", Maven does.
Maven comes with a build lifecycle made of phases (e.g. compile
, test
, package
, etc) and default Lifecycle Bindings (plugins goals bound to phases) which depend on the packaging of your project. And as user, you invoke a phase
(e.g. package
) and Maven then uses specific plugin goals to actually do the job.
For example, for a project with a packaging
of type jar
, the goal bound to package
is jar:jar
and Maven will package your project as JAR. For a project with a packaging
of type war
, war:war
is bound to package
and Maven would produce a WAR during package
. And so on.
The benefit of this approach is that regardless of the project type (jar
, war
, ear
, etc), you don't need to know the details to build it. You just need to know "known" phases : compile
will compile a project, test
will compile and run tests, package
will package it, etc.
On the documentation page, there were some parameters listed for this goal but what I was looking for is how one places them in the 'goal' or 'executions' tag.
The Guide to Configuring Plug-ins explains the rules to configure any Maven plugin, which is done by specifying a <configuration>
element. This <configuration>
can be either generic (global) or specific to an <execution>
for goals that participate to a particular phase of the build lifecycle. And once you know how to configure one of them, you can configure any of them (only the parameters are specific to each plugin).
In the particular case of the Maven JAR Plugin, a global <configuration>
should suffice, it's unlikely that you'll need a special <execution>
(additional to the default one).