------ Usage ------ Jerome Lacoste Dennis Lundberg Olivier Lamy ------ 2011-08-17 ------ ~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ~~ NOTE: For help with the syntax of this file, see: ~~ http://maven.apache.org/doxia/references/apt-format.html Usage Some brief examples on how to use this plugin. If you want to use advanced configurations you should have a look at the documentation for {{{http://maven.apache.org/shared/maven-archiver/}Maven Archiver}}. To handle archiving this version of Maven JAR Plugin uses {{{http://maven.apache.org/shared/maven-archiver/index.html}Maven Archiver}} ${mavenArchiverVersion}. <> Originally, this plugin was meant to sign JARs as well. As of version 2.3, the corresponding goals are no longer supported and users are advised to use the dedicated {{{http://maven.apache.org/plugins/maven-jarsigner-plugin/}Maven Jarsigner Plugin}} instead. * How to build a JAR file If the packaging of your project is set to 'jar', this plugin is executed whenever it passes the "package" phase. You can execute it using the command below: +-----------------+ mvn package +-----------------+ In your project's <<>> directory you'll able to see the generated jar file. * How to include/exclude content from jar artifact Specify a list of fileset patterns to be included or excluded by adding <<<\>>>/<<<\>>> or <<<\>>>/<<<\>>> in your <<>>. +-----------------+ ... ... org.apache.maven.plugins maven-jar-plugin ${project.version} **/service/* ... ... +-----------------+ Note that the patterns need to be relative to the path specified for the plugin's <<>> parameter. * How to create an additional attached jar artifact from the project Specify a list of fileset patterns to be included or excluded by adding <<<\>>>/<<<\>>> or <<<\>>>/<<<\>>> and add a <<>> in your <<>>. <> the jar-plugin must be defined in a new execution, otherwise it will replace the default use of the jar-plugin instead of adding a second artifact. The <<>> is also required to create more than one artifact. +-----------------+ ... ... org.apache.maven.plugins maven-jar-plugin ${project.version} package jar client **/service/* ... ... +-----------------+ * How to create a jar containing test classes When you want to create a jar containing test-classes, you would probably want to reuse those classes. There are two ways to solve this: * Create an attached jar with the test-classes from the current project and loose its transitive <<>>-scoped dependencies. * Create a separate project with the test-classes. [] ** The easy way You can produce a jar which will include your test classes and resources. +-----------------+ ... ... org.apache.maven.plugins maven-jar-plugin ${project.version} test-jar ... ... +-----------------+ To reuse this artifact in an other project, you must declare this dependency with classifier test-jar : +-----------------+ ... groupId artifactId test-jar version test ... +-----------------+ <> The downside of this solution is that you don't get the transitive <<>>-scoped dependencies automatically. Maven only resolves the <<>>-time dependencies, so you'll have to add all the other required <<>>-scoped dependencies by hand. ** The preferred way In order to let Maven resolve all <<>>-scoped transitive dependencies you should create a separate project. +-----------------+ groupId artifactId-tests version ... +-----------------+ * Move the sources files from <<>> you want to share from the original project to the <<>> of this project. The same type of movement counts for the resources as well of course. * Move the required <<>>-scoped dependencies and from the original project to this project and remove the scope (i.e. changing it to the <<>>-scope). And yes, that means that the junit dependency (or any other testing framework dependency) gets the default scope too. You'll probably need to add some project specific dependencies as well to let it all compile again. Now you have your reusable test-classes and you can refer to it as you're used to: +-----------------+ ... groupId artifactId-tests version test ... +-----------------+ For full documentation, click {{{./plugin-info.html}here}}.