NOTE: This page contains drafts of user contributed FAQ entries. The content you see here might not be fully fool-proof or might not comply with the best practices promoted by Maven. What is only guaranteed is that they have worked once for some members. It is best to treat these items as "works in progress" until they have been reviewed and promoted to the main Maven documentation site.
Please follow the format that is being used because it will help in our automated extraction of material which can then be incorporated into the main site.
Unanswered Questions
This page serves as a collection of questions with answers. If you have a frequently asked question that doesn't yet have an answer, please list that question on the other page.
Answered Questions (Index)
Reports & Site Docs
How do I merge a list of configuration items in a parent POM with those in a child POM?
Why do I not get an index.html page generated for my project website?
How do I include/exclude the other modules in the navigation menu in the parent site?
How do I create a report that does not require Doxia's Sink interface?
How do I generate Maven plug-in sites, with pages that include an overview of the goals and parameters for each plug-in?
Is there a site.xml DTD?
How do I integrate static (x)html into a Maven site?
Where do I configure report plug-ins, like javadoc?
Is there a way to get Maven to report the number of compile errors found?
How do I convert my <reports> from Maven 1 to Maven 2?
Handle special characters in site
How do I add a description to the welcome page of the generated site when I execute mvn site?
Which part in pom.xml the javadoc plugin should be configured?
Eclipse
How do I specify which output folders the Eclipse plugin puts into the .classpath file?
Where can I get the Maven 2 plugin for Eclipse?
I issued- mvn -Declipse.downloadSources=true eclipse eclipse goal. It created .classpath and .project for both modules, and in my local repository it downloaded sources Ho do I access them in eclipse?
Is it possible that if I do mvn eclipse eclipse goal that my project would get disconnected from the subversion repository?
Does it matter if the project's directory name is not the same as the artifactId?
Plugins
no-valid-version How do I resolve the " < plugin name > does not exist or no valid version " error?
How do I list available plugins?
How do I get a plug-in's dependencies from a Mojo?
How do I locate a required plug-in?
How do I determine what version of a plugin I am using?
How do I use SNAPSHOT versions of plug-ins?
Is there a property file for plug-in configuration in Maven 2.0?
I've just created a maven plugin. Is there a sample plugin integration test I can use?
The snapshot version of the plugin is not updated in the snapshot repo, What should I do to update my copy of the plugin?
How to list all goals available for a certain plugin?
What does the 'You cannot have two plugin executions with the same (or missing) <id/> elements' message mean?
How do I execute the assembly plugin with different configurations
Where is the plugin-registry.xml?
How do I know which phase a plug-in is associated with?
POM
How do I install a file in my local repository along with a generic POM
How do I install a file in my local repository along with my customized POM?
Does the v4.0.0 POM include a < versions/ > element?
How do I read the version from the pom.xml and then using Java display the version on my application?
How do I determine which POM contains missing transitive dependency?
Does a POM inherit its resources?
Is it possible to specify multiple(s) in a POM at a greater depth than 1 level?
Is there a way to read and examine the contents of a pom.xml file from inside an application?
Is there a way to use the current date in the POM?
Where are the Maven XSD schemas?
Dependencies
How do I implement "maven.jar.override" of Maven 1 with Maven 2?
Why there are no dependency properties in Maven 2?
How to make a war artifact as a dependency?
Can I disable transitive dependencies?
Is there a preferred way to communicate dependencies in documentation?
Are there any recommendations on how to handle dependencies, which aren't always required?
How do I determine my project's transitive dependencies, and if needed, exclude a particular transitive dependency?
If two versions of the same dependency are at the same depth, how do you know or predict which version will be used?
Inheritance
How can I have a child project not inherit a goal (like install) from the parent?
What is Maven's order of inheritance?
How do I specify that all web modules will inherit the group's common files from a parent web module?
Repository
How do I prevent verification warnings with custom repositories?
How do I access artifacts if Ibiblio is down?
How do I specify my remote repo in Maven 2.0?
How do I install artifacts to a remote repository?
Repository precedence
List of available maven 2 mirrors.
How do I change the default remote repository?
How to remove the artifact in the local repository?
What is the purpose of remote repository (other than ibilbilo)?
Errors
[#Why do I get java.lang.NoClassDefFoundError: org/codehaus/classworlds/Launcher when I try to execute Maven?]
What does the "ERROR Cannot override read-only parameter < parameter_name>" message, when running mean?
What does the FATAL ERROR with the message *'Class org.apache.commons.logging.impl.Jdk14Logger does not implement Log'* when using the maven-checkstyle-plugin mean?
Unsupported Protocol Error when deploying a 3rd party jar. What should I do?
I have my web.xml in my customed directory layout for my webapp, but why am I getting the error "Deployment descriptor <Path>\WEB-INF\web.xml does not exist"?
How can I stop this "WARNING While downloading artifactId-artifactId-version This artifact has been relocated to groupId-artifactId-version"?
Why do i get an 'error downloading artifact' message when building with Maven 2 under Fedora Core 4 and Java 1.4?
Supported Features
Does Maven 2.x support pre/postGoals?
How does maven 2 implement reproducibility?
Maven Comparisons
What is the difference between Maven and Ivy?
Ant
How can I use Ant tasks in Maven 2?
How do I run an ant task twice, against two different phases?
Can I define the antrun plug-in to be executed on demand?
How do I generate sources with the antrun plug-in?
How do I setup the classpath of my antrun plugin to use the classpath from maven?
Mojo
How do I get the project's sources from a Mojo?
How do I properly populate variables, when extending a mojo from another plugin?
How do I determine the stale resources in a Mojo to avoid reprocessing them?
How do I create a command line parameter (i.e., -Dname=value ) in my mojo?
What does aggregator mean in mojo?
What would it take for the MOJO one to get out of the sandbox?
How do I indicate array types in a MOJO configuration?
Deploy
How do I deploy my binary during the deploy phase?
How do I invoke the 'maven dist' function from Maven 1.0, in Maven 2.0?
Is there a way to use the deploy phase to perform some tasks without maven trying to install the artifact to a maven repository?
Is maven 'deploy' goal and actually copying of a dependency or artifact jar to remote repository same?
Profiles
Can a profile inherit the configuration of a "sibling" profile?
Testing
How do I prevent tests from running twice, after adding a configuration for the surefire plugin?
How do I skip unit tests when building a project?
Is there a setting for testing, where I can add a directory to the classpath, which will allow the tests to access the files?
Why does Maven compile my test classes but don't run them?
Compile
How do I compile 1.3 java sources with a 1.4.x or 1.5.x JDK?
Building modules only when they have changed
Adding or Excluding
Can I add a java source to my war package?
How do I filter which classes should be put inside the packaged jar?
Is it possible to exclude a package from the generated jar file?
How not to include all jar files from parent pom?
How do I filter resources in the war?
How do I prevent including JARs in WEB-INF/lib? I need a "compile only" scope!
Changing Locations
How can I change the default location of the generated jar when I command "mvn package"?
Is there a way to specify a different output directory without having to edit the pom or configuration file each time I do a build?
How do I set the base directory for creating the packages created by assembly?
Is it possible to create my own directory structure?
JDK
I would like clarification on what version of the JDK is required for m2 -- particularly with respect to creating Plugins.
i'm wondering what a "snapshot" actually is.
How do I configure a project to use a specific version of a JDK?
Other
Maven doesn't work, how do I get help?
How do I get a list of archetypes?
How do I add main class in a generated jar's manifest?
How do I run a build/package/deploy process without waiting for reports or unit tests, so that I can quickly deploy to an integration box?
Where is the source code? I couldn't seem to find a link anywhere on the Maven2 site.
How do I configure the equivalent of maven.war.src of war plugin in Maven 2.0?
How do I add my generated sources to the compile path of Maven, when using modello?
Where can I get offline documentation for Maven?
What is the purpose of displaying read-only, plug-in fields in user documentation, if they are not configurable in the project descriptor?
How can I disable the timestamp appended in my deployed artifact?
How to run a java program from M2?
Where to find the source code for org.apache.maven.model package?
How can I reference windows or unix environment variables in my POM?
Where to get sun.jdk-tools-jar-1.4.0 on MacOSX?
How can I make the war plugin produces an exploded war instead of .war file?
Is there any variable to determine what version of an artifact was deployed after the deploy step runs?
How do I get the top line of a table to be "headers" for that column in APT?
What is the suggested way to download a remote file?
How do I install the package generated by the assembly plugin to be installed in the local repository?
Is it possible to use HashMap as configurable parameter in a plugin? How do I configure that in pom.xml?
Which plugins have StarTeam (SCM) support? How do they differ?
How should I point a path for maven 2 to use a certain version of JDK when I have different versions of JDK installed on my PC and my JAVA_HOME already set?
Why does release prepare goal requires the project to be released be a snapshot? Is it possible to do a release prepare from a parent project? What about from a sub-project?
How can I create an archetype with resources mapped to the class files directory?
What does (f) and (s) debug output mean?
How to resolve problems with jtaxxx.jar?
How to make Continuum work in service mode when an Error 1067 is reported?
Using xdoclet, how come "<fileset dir="src/main"><include name="/beans//*Bean.java"/></fileset>" does not work?
I don't have a domain name and I don't want use my employer's domain name. What should I name my plugin package?
pom.xml or settings.xml? What is the best practice configuration usage for these files?
What is reactorProjects? executedProject?
What is a Snapshot?
Whenever a file is modified in a maven project how is the SNAPSHOT jar updated in the remote repository?
Does maven support automated build and test from non-Java applications?
What would be the appropriate way to enable inheritance of classes in the test hierarchy across modules during the test-compile phase of a multi-pom project?
Answered Questions
How do I merge a list of configuration items in a parent POM with those in a child POM?
Since plugin configurations are handled as XML DOM instances by the core, there is an ever-present struggle between when to merge child elements' values with one another (when the child's <source> overrides the parent's, for example), and when you want to append new child elements to the existing list (as in the example above, or any time you have a list of items to aggregate during inheritance).
We've solved this problem using an attribute, 'combine.children'. You simply specify this attribute, with the value of "append" at the parent element where such aggregation should occur, and Maven will switch its merge behavior for that element's children.
NOTE: I fixed this behavior in Maven's trunk; previously, it had been putting the parent POM's sub-elements AFTER those of the child. This is inconsistent with other inheritance functions, so I've reversed the ordering to truly append the child's elements.
So, to recap:
parent:
<configuration>
<items>
<item>one</item>
<item>two</item>
</items>
</configuration>
child:
<configuration>
<items combine.children="append">
<item>three</item>
</items>
</configuration>
result:
<configuration>
<items>
<item>one</item>
<item>two</item>
<item>three</item>
</items>
</configuration>
(If you're using an earlier version of Maven than trunk (revId 545315), the order above will be three, one, two.)
Why do I not get an index.html page generated for my project website?
The usual cause of this is configuring maven-project-info-reports plugin and leaving out the 'index' report.
How do I resolve the " < plugin name > does not exist or no valid version " error?
This error indicates that Maven is either unable to access the required plug-in from your local repository, or unable to access the official or 'central' Maven2 plug-in repository.
To resolve this error:
- If you are behind a http proxy, please check the Maven2 proxy settings guide.
- If you are upgrading Maven from an older version, try running with -U. This will force an update check on all plug-ins.
If the error persists, browse archived discussions, post to the Maven user list, or log a ticketdescribing your problem, if you think it is a bug. Tickets may also be issued for feature enhancement requests, and other tasks.
There is a known issue with Maven as of 2.0.4 which is related to metadata files being corrupted during plugin version resolution. For more information, and for a workaround, see MNG-2408.
Dependencies
How do I implement "maven.jar.override" of Maven 1 with Maven 2?
Assume you have an open source project on Source Forge which uses some 3rd party libraries which are not available in any public Maven repository. Still, you want to build your project with Maven 2 - how to deal with those unavailable dependencies? Maven 1 allowed to override the path of files of dependencies, with a relative path, for example to a .jar file included in the projects' CVS structure. Maven 2 does not support that, so one way to achieve the same thing is:
- Create a multi-module project. The first module contains the local 3rd-party jar files, at any location, with any name. As a simple example, just one file, under the path "src/build/jars/acme-worker12.jar"
- The purpose of the first sub-module is to install the 3rd party .jar file into your local Maven 2 repository through the maven "install" plugin. This plugin allows to install any given file under any "groupId", "artifactId" and "version":
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>copy-acme</id>
<phase>validate</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>${basedir}/src/build/jars/acme-worker-12.jar</file>
<groupId>acme</groupId>
<artifactId>worker</artifactId>
<version>1.2</version>
<packaging>jar</packaging>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
- In the second module, where your actual project code is, create a dependency based on the "groupId", "artifactId" and "version" that you used to install the 3rd party libary.
<dependencies>
<dependency>
<groupId>acme</groupId>
<artifactId>worker</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
One word of caution, though; if you include - for whatever reason Junit like that, it MUST be deployed under - and referred to as - the group id "junit", or the build will break, due to some hardwired dependencies of the current Surefire plugin.
Errors, Dependencies, Plugins
How do I install a file in my local repository along with a generic POM?
This solution requires at least 2.0.1-SNAPSHOT or above version of Maven 2. You may do this by typing this command (please take note that this is a single line only).
mvn install:install-file
-DgroupId=<group-id>
-DartifactId=<artifact-id>
-Dversion=<version>
-Dfile=<path-to-file>
-Dpackaging=<packaging> (i.e. jar)
-DgeneratePom=true
This command installs the jar in your local repository with the generated generic pom.
Well, this doesn't work in Maven 2.0.2. It just gives the message "Cannot execute mojo: install-file. It requires a project with an existing pom.xml, but the build is not using one." --kreiger@imcode.com
This worked fine for me using Maven 2.0.4 without a pom.xml file --cdoremus
Repositories
How do I install a file in my local repository along with my customized POM?
The solution requires at least 2.0.1-SNAPSHOT or above version of Maven 2 and add the -DpomFile=<path-to-pom> parameter just like the sample below.
mvn install:install-file
-DgroupId=<group-id>
-DartifactId=<artifact-id>
-Dversion=<version>
-Dfile=<path-to-file>
-Dpackaging=<packaging> (i.e. jar)
-DpomFile=<path-to-pom>
This command will install the file in your local repository along with your customed pom.
Repositories
How do I include/exclude the other modules in the navigation menu in the parent site?
http://jira.codehaus.org/browse/MNG-661, provides a simple patch which provides parent and module links using the project URLs which as you
correctly point out only work when the site is deployed.
Unknown
How do I locate a required plug-in?
If you cannot find a certain plugin, you may want to take a look on the following sites.
- http://mojo.codehaus.org
- https://svn.codehaus.org/mojo/trunk/mojo
- https://svn.codehaus.org/mojo/trunk/mojo/mojo-sandbox
Plugins & Lifecycle
Does Maven 2.x support pre/postGoals?
Maven 2.x no longer supports pre/postGoals, which were used in Maven 1.x to inject custom behavior to the build process. This caused a problem, since declaring your code to be a preGoal of some other goal meant that you depended on that specific goal, rather than the work it did. It also caused confusion when trying to inject other behavior into a build that already had pre/postGoals attached: Where would the new behavior be injected?
Pre- and post-goals in Maven 1.x were usually used to develop the concept of a workflow, or lifecycle, for the build, where x happened before y, which had to happen before the sources could be compiled. In Maven 2, we've incorporated this concept of a build lifecycle natively. The steps - or phases - in this lifecycle correspond to the types of actions that might occur in a build. Your plugin can declare which type of action it performs - or which phase it should bind to - and that will guarantee it is executed before the next action type. For example, if your plugin generates some source code, you might want it to bind to the "generate-sources" lifecycle phase, so it is guaranteed to run before the "compile" phase.
For more information, see:
General
What is the difference between Maven and Ivy?
For a comparison of Maven's features vs Ivy's you can refer to our feature comparison
General
How do I get a plug-in's dependencies from a Mojo?
public class MyMojo
extends AbstractMojo
{
/**
* @parameter expression="${plugin.artifacts}"
* @required
*/
private List pluginArtifacts;
public void execute()
throws MojoExecutionException
{
...
for ( Iterator i = pluginArtifacts.iterator(); i.hasNext(); )
{
Artifact pluginArtifact = (Artifact) i.next();
}
...
}
}
Unknown
How do I get the project's sources from a Mojo?
public class MyMojo
extends AbstractMojo
{
/**
* @parameter expression="${project.compileSourceRoots}"
* @required
*/
private List sourceRoots;
public void execute()
throws MojoExecutionException
{
...
for ( Iterator i = sourceRoots.iterator(); i.hasNext(); )
{
String sourceRoot = (String) i.next();
}
}
}
Unknown
Does the v4.0.0 POM include a < versions/ > element?
The POM does not inlcude a < versions/ > element. The POM reflects the current state of a project's build only, not a historical build log. The POM is not designed to track historical information, as it would be difficult for developers to always add this information manually, i.e., to always remember to add it or to ensure that the correct information is added when multiple branches are involved.
However, if the SCM tag of the <scm> section of the POM is populated, the repository records build versions, enabling developers to reconstruct the information for each released build.
POM, General
How do I create a report that does not require Doxia's Sink interface?
Make it a report and override the isExternalReport() method to return true.
Sites & Reporting
How do I prevent verification warnings with custom repositories?
Warnings from custom repositories (usually located within the organization's network, or even on the same workstation) are triggered when Maven tries to verify the integrity of the files in the repository. This verification is done via the SHA1 or MD5 sum of the file. If these sum files do not exist, then a warning appears.
Support for downloading the security sum files is not yet included in the Maven2 distribution. There are free command-line utilities on the Internet that generate these sums. Below is an example of a bash script (use Cygwinif you are using a windows machine) that generates sha1sum for all jar, xml and pom files contained in the directory where it is executed:
#!/usr/bin/bash
gensum(){
shaname=$1.sha1
sum=`sha1sum $1 | cut -f1 -d" "`
echo $sum > $shaname
}
processFile(){
while read oneline
do
gensum $oneline
done < "$1"
}
tmpFile=$TMP/shagen.list
echo "Generating sha1 sums for XML files"
find . -name "*.xml" > "$tmpFile"
processFile "$tmpFile"
echo "Generating sha1 sums for POM files"
find . -name "*.pom" > "$tmpFile"
processFile "$tmpFile"
echo "Generating sha1 sums for JAR files"
find . -name "*.jar" > "$tmpFile"
processFile "$tmpFile"
rm "$tmpFile"
The script above has been tested on
Cygwin and is provided "as-is" and with no guarantee.
Errors, Repositories
What does the "ERROR: Cannot override read-only parameter: < parameter_name > " message, when running <plugin_name>: mean?
This means that the parameter being overriden in the pom.xml is read-only. Hence, it is not possible to override this parameter.
Errors, POM
How do I generate Maven plug-in sites, with pages that include an overview of the goals and parameters for each plug-in?
Include maven-plugin-plugin as a report.
Plugin Requests, Sites & Reporting
Can I define the antrun plugin to be executed on demand like "mvn antrun:run"?
The antrun plugin can be executed on demand only if:
- the top level configuration of the plugin contains all the information
- a variable is passed from the command line, eg -Dtarget=foo antrun:run
- the appropriate target in the script is executed based on the variable
However, it is recommended that developers write plugins for their goals (Ant support for
plugins will be available soon, currently you must write them in java or beanshell).
Plugins and Lifecycle, Ant-related
How do I properly populate variables, when extending a mojo from another plugin?
When creating plugins, the field metadata is read from source files, so it is not available when the original source is not available. While the metadata is available in the plugin in META-INF/maven/plugin.xml, currently, there is no way to incorporate it when building a new plugin.
It is currently recommended that plug-ins be built using composition, instead of inheritence.
Plugin Requests, Design, Patterns & Best Practices
How do I access artifacts if Ibiblio is down?
To access artifacts if Ibiblio is down, use any of its mirror sites.
http://maven.apache.org/guides/mini/guide-mirror-settings.html
Repositories, General
How do I get a list of archetypes?
To get a list of archetypes, refer to the following page http://svn.apache.org/viewcvs.cgi/maven/archetype/trunk/maven-archetypes
Unknown
How do I specify my remote repo in Maven 2.0 (i.e., what is the equivalent of 'maven.repo.remote' in Maven 1.x)?
To specify a remote repo in Maven 2.0, add the <repositories> element to the POM:
<repositories>
<repository>
<id>my-repo2</id>
<name>your custom repo</name>
<url>http://jarsm2.dyndns.dk</url>
</repository>
</repositories>
Or, refer to the following page
http://maven.apache.org/guides/mini/guide-multiple-repositories.html
Repositories
How do I specify which output folders the Eclipse plugin puts into the .classpath file?
<build>
...
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<outputDirectory>target-eclipse</outputDirectory>
</configuration>
</plugin>
</plugins>
</pluginManagement>
...
</build>
Plugins and Lifecycle, IDEs
How do I invoke the "maven dist" function from Maven 1.0, in Maven 2.0?
mvn assembly:assembly
See the Assembly Plugin documentation for more details.
General, Plugins and Lifecycle
Can a profile inherit the configuration of a "sibling" profile?
No. Profiles merge when their ID's match - so you can inherit them from a parent POM (but you can't inherit profiles from the same POM).
Inheritence and Interpolation, Plugins and Lifecycle, POM
How do I run an ant task twice, against two different phases?
You can specify multiple execution elements under the executions tag, giving each a different id and binding them at different phases.
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
* <id>one</id>*
<phase>generate-sources</phase>
<configuration>
<tasks>
<echo message="generate-sources!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
*<id>two</id>*
<phase>package</phase>
<configuration>
<tasks>
* <echo message="package!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"/>*
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Ant-related
How do I prevent tests from running twice, after adding a configuration for the surefire plugin?
Declare the configuration outside of the executions tag of the plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.0</version>
<configuration>
<systemProperties>
<property>
<name>net.sourceforge.cobertura.datafile</name>
<value>C:\cobertura.ser</value>
</property>
</systemProperties>
</configuration>
</plugin>
Plugins and Lifecycle, Sites & Reporting
How do I integrate static (x)html into my Maven site?
You can integrate your static pages in this several steps,
- Put your static pages in the resources directory, ${basedir}/src/site/resources.
- Create your site.xml and put it in ${basedir}/src/site. An example below:
<project name="Maven War Plugin">
<bannerLeft>
<name>Maven War Plugin</name>
<src>http://maven.apache.org/images/apache-maven-project.png</src>
<href>http://maven.apache.org/</href>
</bannerLeft>
<bannerRight>
<src>http://maven.apache.org/images/maven-small.gif</src>
</bannerRight>
<body>
<links>
<item name="Maven 2" xhref="http://maven.apache.org/maven2/"/>
</links>
<menu name="Overview">
<item name="Introduction" xhref="introduction.html"/>
<item name="How to Use" xhref="howto.html"/>
</menu>
${reports}
</body>
</project>
- Link the static pages by modifying the <menu> section, create items and map it with the filename of the static pages.
<menu name="Overview">
<item name="Introduction" xhref="introduction.html"/>
<item name="How to Use" xhref="howto.html"/>
<item name="<put-name-here>" xhref="<filename-of-the-static-page>"/>
</menu>
Sites & Reporting
How do I specify that all web modules will inherit the group's common files from a parent web module?
maven-war-plugin 2.0-beta-3 and later supports merging of wars. Just reference the common WAR project from another WAR project as a dependency of <type>war</type> and it will automatically be merged.
See http://jira.codehaus.org/browse/MWAR-8
Inheritence and Interpolation
How do I determine which POM contains missing transitive dependency?
run "mvn -X"
POM, Dependencies
Is there a property file for plug-in configuration in Maven 2.0?
No. Maven 2.x no longer supports plug-in configuration via properties files. Instead, in Maven 2.0 you can configure plug-ins directly from command line using the -D arguement, or from the plug-in's POM using the <configuration> element.
General, POM, Plugins and Lifecycle, Command Line
How do I determine the stale resources in a Mojo to avoid reprocessing them?
This can be done using the following piece of code:
import org.codehaus.plexus.compiler.util.scan.InclusionScanException;
import org.codehaus.plexus.compiler.util.scan.StaleSourceScanner;
import org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping;
StaleSourceScanner scanner = new StaleSourceScanner( 0, Collections.singleton( "**/*.xml" ), Collections.EMPTY_SET );
scanner.addSourceMapping( new SuffixMapping( ".xml", ".html" ) );
Set<File> staleFiles = (Set<File>) scanner.getIncludedSources( this.sourceDirectory, this.targetDirectory );
The second parameter to the StaleSourceScanner is the set of includes, while the third parameter is the set of excludes. You must add a source mapping to the scanner (second line). In this case we're telling the scanner what is the extension of the result file (.html) for each source file extension (.xml). Finally we get the stale files as a Set<File> calling the getIncludedSources method, passing as parameters the source and target directories (of type File). The Maven API doesn't support generics, but you may cast it that way if you're using them.
In order to use this API you must include the following dependency in your pom:
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-api</artifactId>
<version>1.5.1</version>
</dependency>
</dependencies>
POM, Plugin API
What does the FATAL ERROR with the message "Class org.apache.commons.logging.impl.Jdk14Logger does not implement Log" when using the maven-checkstyle-plugin mean?
Checkstyle uses commons-logging, which has classloader problems when initialized within a Maven plugin's container. This results in the above message - if you run with '-e', you'll see something like the following:
—
Caused by: org.apache.commons.logging.LogConfigurationException: org.apache.commons.logging.LogConfigurationException: Class org.apache.commons.logging.impl.Jdk14Logger does not implement Log
—
buried deep in the stacktrace.
The only workaround we currently have for this problem is to include another commons-logging Log implementation in the plugin itself. So, you can solve the problem by adding the following to your plugin declaration in your POM:
<project>
...
<build>
...
<plugins>
...
<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.12</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
...
<reporting>
...
<plugins>
</plugins>
</reporting>
</project>
While this may seem a counter-intuitive way of configuring a report, it's important to remember that Maven plugins can have a mix of reports and normal mojos. When a POM has to configure extra dependencies for a plugin, it should do so in the normal plugins section.
We will probably try to fix this problem before the next release of the checkstyle plugin.
UPDATE: This problem has been fixed in the SVN trunk version of the checkstyle plugin, which should be released very soon.
Plugins and Lifecycle, Sites & Reporting, Errors
Where do I configure report plug-ins, like javadoc?
Generally, you should configure reporting in the <reporting> (vs. <build>) section of the POM. Configuration there applies to both the site, and when run on the command line, and adding the plugin there adds the report to the generated site.
Configuration in the build section is only used during the normal lifecycle or the command line invocation (eg javadoc:javadoc).
Configuration should go there if you do not want the report on the site, or the configuration differs from what is on the site (eg, some plugins have a fail build option).
Sites & Reporting, Plugins and Lifecycle, Command Line
How do I deploy my binary during the deploy phase?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>assembly</goal>
</goals>
<configuration>
</configuration>
</execution>
</executions>
</plugin>
Then run "mvn deploy".
Deployment
How do I add main class in a generated jar's manifest?
Configure the maven-jar-plugin and add your main class.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.mycompany.app.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
Unknown
How do I install artifacts to a remote repository?
You need at least 2.1-SNAPSHOT version of maven-deploy-plugin to make this work, current workaround to use this is to copy the wagon provider jar (ie. wagon-ftp-1.0-alpha-3.jar) in your %M2_HOME%/lib and execute the command:
mvn deploy:deploy-file
-DgroupId=<groupId>
-DartifactId=<artifactId>
-Dversion=<version>
-Dpackaging=<packaging>
-Dfile=<path-to-file>
-DrepositoryId=<id-to-map-on-server>
-Durl=<url-of-remote-repo>
Repositories, Command Line
Does a POM inherit its resources?
Yes, resources are inherited, but only if the child pom does not define any resources. If it does, then the project just uses those resources defined in its pom and the parents resources are overridden.
POM, Inheritence and Interpolation
How do I use SNAPSHOT versions of plug-ins?
http://maven.apache.org/guides/development/guide-testing-development-plugins.html
Unknown
How do I run a build/package/deploy process without waiting for reports or unit tests, in order to quickly deploy to an integration box?
You could create a specific profile that skips the reporting and test phases.
Also refer to [How do I skip unit tests when building a project?]
Unknown
How do I configure the equivalent of maven.war.src of war plugin in Maven 2.0?
<build>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warSourceDirectory></warSourceDirectory>
</configuration>
</plugin>
</plugins>
...
</build>
See
http://maven.apache.org/plugins/maven-war-plugin/war-mojo.html for other configurable properties of the war plugin.
Unknown
How do I execute the assembly plugin with different configurations?
Add this to your pom,
<build>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>1</id>
<phase>install</phase>
<goals>
<goal>assembly</goal>
</goals>
<configuration>
<descriptor>src/main/descriptors/bin.xml</descriptor>
<finalName>${project.build.finalName}-bin</finalName>
</configuration>
</execution>
<execution>
<id>2</id>
<phase>install</phase>
<goals>
<goal>assembly</goal>
</goals>
<configuration>
<descriptor>src/main/descriptors/src.xml</descriptor>
<finalName>${project.build.finalName}-src</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
...
</build>
and run mvn install, this will execute the assembly plugin twice with different config.
Unknown
What is Maven's order of inheritance?
- parent pom
- project pom
- settings
- CLI parameters
where the last overrides the previous.
General, Inheritence and Interpolation, Design, Patterns & Best Practices
How do I add my generated sources to the compile path of Maven, when using modello?
Modello generate the sources in the generate-sources phase and automatically adds the source directory for compilation in maven. So you don't have to copy the generated sources.
You have to declare the modello-plugin in the build of your plugin for source generation (in that way the sources are generated each time).
Plugins and Lifecycle
Can I add a java source to my war package?
You can't, but you can use the assembly plugin to create a source distribution and a binary distribution for your project
Please refer to these sites for more info
http://maven.apache.org/guides/mini/guide-assemblies.html
http://maven.apache.org/plugins/maven-assembly-plugin/howto.html
Deployments, Plugins and Lifecycle
Is there a site.xml DTD?
There is no DTD but XSD.
http://maven.apache.org/maven-navigation-1.0.xsd
Sites & Reporting
What does the "You cannot have two plugin executions with the same (or missing) <id/> elements" message mean?
It means that you have executed a plugin multiple times with the same <id>. Provide each <execution> with a unique <id> then it would be ok.
Errors, Plugins and Lifecycle
Can I disable transitive dependencies?
No you can't, but you may exclude the dependencies you dont want to include in your project.
Following is a sample on how to exclude transitive dependencies.
<project>
...
<dependency>
<groupId></groupId>
<artifactId></artifactId>
<version></version>
<scope></scope>
<exclusions>
<exclusion>
<groupId></groupId>
<artifactId></artifactId>
</exclusion>
</exclusions>
</dependency>
</project>
Dependencies, Design, Patterns & Best Practices
Where can I get offline documentation for Maven?
Check it out from http://svn.apache.org/repos/asf/maven/site/trunk and run mvn site:site
General, Sites & Reporting
How do I skip unit tests when building a project?
Run the mvn command with "-Dmaven.test.skip=true" argument.
Also see [How do I run a build/package/deploy process without waiting for reports or unit tests, so that I can quickly deploy to an integration box?]
How do I convert my <reports> from Maven 1 to Maven 2?
In m1, we declare reports in the pom like this:
<project>
...
<reports>
<report>maven-checkstyle-plugin</report>
<report>maven-pmd-plugin</report>
</reports>
</project>
In m2, the <reports> tag is replaced with <reporting>
<project>
...
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<configuration>
</configuration>
</plugin>
</plugins>
<reporting>
</project>
Sites & Reporting, General
How do I create a command line parameter (i.e., -Dname=value ) in my mojo?
In your mojo, put "expression=${<exp>}" in your parameter field
/**
* @parameter expression="${expression.name}"
*/
private String exp;
You may now able to pass parameter values to the command line.
"mvn -Dexpression.name=value install"
Command Line
What is the purpose of displaying read-only, plug-in fields in user documentation, if they are not configurable in the project descriptor?
Often, parameters are specified as read-only to indicate that its value should be changed indirectly, rather than in the plugins <configuration/> section. For instance, I may have a plugin that declares a parameter as such:
/**
* @parameter default-value="${project.build.directory}"
* @required
* @readonly
*/
private File buildDir;
In this case, my plugin wants to output something to the project's build directory. If this were configured directly on the plugin, it might not be cleaned up when the user issued
'mvn clean', so instead I mark it as
@readonly. This tells the user that she should modify the structure referenced by
default-value(i.e. <project><build><directory/> in the POM) instead, which will allow this plugin to be a good citizen in the build process.
Unknown
I've just created a maven plugin. Is there a sample plugin integration test I can use?
Each integration test is a separate project. For a plugin, you may want to create a project that will use your plugin and probably put it inside src/test/projects like maven-antrun-plugin, maven-eclipse-plugin, maven-javadoc-plugin and several others. These plugins can be found here: https://svn.apache.org/repos/asf/maven/plugins/trunk
Plugins and Lifecycle, Sites & Reporting, Integration tests
The snapshot version of the plugin is not updated in the snapshot repo, What should I do to update my copy of the plugin?
If the plugin in the snapshot repo (http://snapshots.maven.codehaus.org/maven2) is not yet updated. The only way to update it is to check out the source from SVN and build it.
Unknown
Is there a way to get Maven to report the number of compile errors found?
Currently, this type of summary information is not built into the compiler plugin, but it would be possible to add. If this feature is important to you, add your vote to MNG-1854.
Sites & Reporting
In a multi-module project, is there any way for maven to build only those modules that have changed from the previous build and leave the unchanged modules alone (i.e. not build them)?
Currently, this is not possible. The main reason is that it's a non-trivial to determine whether an entire project's build is stale (the project here being one of the modules). It will be dependent on the phase being called, and the packaging of the particular module. This type of feature would have to be included in a design discussion on the Maven 2.1 Discussion Wiki.
Design, Patterns & Best Practices
Where can I get the Maven 2 plugin for Eclipse?
http://maven.apache.org/eclipse-plugin.html
There are some flash demos to show the user how to use the plugin.
IDEs
Handle special characters in site
A solution with eclipse and solaris
In eclipse.ini :
Adding -Dfile.encoding=ISO-8859-1
If using xmlbuddy with eclipse to edit xdoc files set the encoding
Honor encoding
Default to ISO-8859-1
Configuration in pom
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<configuration>
<outputEncoding>UTF-8</outputEncoding>
</configuration>
</plugin>
On the solaris machine
In $HOME/.profile
MAVEN_OPTS="-Xmx512m -Xms512m -Dfile.encoding=ISO-8859-1" (mx/ms not mandatory for m2 but for m1).
LANG=en_US.ISO8859-15
Sites & Reporting, IDEs
How do I generate sources with the antrun plug-in?
For instance to generate sources add the following to your plugins section
NOTE: this may only work in the latest plugin version in SVN
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<dependencies>
</dependencies>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<tasks>
<path id="classpath">
<path refid="maven.compile.classpath"/>
<path refid="maven.plugin.classpath"/>
</path>
<ant antfile="${basedir}/build.xml" dir="${basedir}" inheritRefs="true">
<target name="generate-sources"/>
</ant>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Ant-related
Where is the plugin-registry.xml?
From the settings.xml, you may enable it by setting <usePluginRegistry/> to true
and the file will be in ~/.m2/plugin-registry.xml
General, Plugins and Lifecycle
Is there a way to specify a different output directory without having to edit the pom or configuration file each time I do a build?
Yes. You can make use of the pom's <properties> element to accomplish this.
To do so, simply add the following fragment to your pom:
<project>
...
<build>
<directory>${directory}</directory>
<outputDirectory>${directory}/classes</outputDirectory>
<testOutputDirectory>${directory}/test-classes</testOutputDirectory>
</build>
<properties>
<directory>target</directory>
</properties>
...
</project>
Now, to specify a different output directory at runtime simply use the directory property as a mvn command line parameter;
mvn -Ddirectory=tmp package
This will send the build's output files to the ${basedir}/tmp directory.
POM, Command Line
How do I compile 1.3 java sources with a 1.4.x or 1.5.x JDK?
You need to specify the <compilerVersion> element to 1.3
i.e.
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<executable></executable>
<compilerVersion>1.3</compilerVersion>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
Unknown
How do I change the default remote repository?
Define in your POM a repository with "central" as the repository id.
<repositories>
<repository>
:
<id>central</id>
<name>any name</name>
<url>http://your.remote.repo.url.org</url>
:
</repository>
</repositories>
Repositories
I have my web.xml in my customed directory layout for my webapp, but why am I getting the error "Deployment descriptor <Path>\WEB-INF\web.xml does not exist"?
You may specify the path of your web.xml in your webapp by configuring maven-war-plugin.
<build>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml></webXml>
</configuration>
</plugin>
</plugins>
</build>
Errors, Deployment
Is it possible to specify multiple <module>(s) in a POM at a greater depth than 1 level?
Yes. This can be done in two ways: 1. add the extra path in the top level POM, or 2. add extra parent poms at different levels, if approriate.
For example, you have the following structure:
/A/pom.xml (multi-module POM)
/A/B/C/pom.xml
/A/B/C/D/pom.xml
And you want the modules at level C and D built when the multi-module POM is built.
For the first solution:
Add the following at the top level POM:
<modules>
<module>A/B</module>
...
<modules>
For the second solution:
Add the following at the top level POM:
<modules>
<module>B</module>
<modules>
And in directory A/B/, add an extra parent POM and add the following:
<modules>
<module>C</module>
<modules>
Both ways are effectively the same, but if you have that inheritance structure, the second gives a more natural grouping (eg, you can cd
into "B" and build all its subprojects only).
If you do the first solution, the children poms should have the following hint in the parent element:
<parent>
...
<artifactId>A</artifactId>
<relativePath>../../pom.xml</relativePath>
</parent>
The repository is still used if ../../pom.xml is not found or the versions don't match, but the hint makes it easier to use local modifications without installing the parent.
POM
How to list all goals available for a certain plugin?
We can use the describe goal of maven-projecthelp-plugin to list the goals available, see sample syntax below.
mvn projecthelp:describe -Dplugin=org.apache.maven.plugins:maven-eclipse-plugin -Dfull=true
This would display all the goals and descriptions of the parameters used by maven-eclipse-plugin.
Plugins and Lifecycle, IDEs
What does aggregator mean in mojo?
When a Mojo has a @aggregator expression, it means that It can only build the parent project of your multi-module-project, the one who has the packaging of pom. It can also give you values for the expression ${reactorProjects} where reactorProjects are the MavenProject references to the parent pom modules.
Unknown
Why there are no dependency properties in Maven 2?
They were removed because they aren't reliable in a transitive environment. It implies that the dependency knows something about the
environment of the dependee, which is back to front. In most cases, granted, the value for war bundle will be the same for a particular
dependency - but that relies on the dependency specifying it.
In the end, we give control to the actual POM doing the building, trying to use sensible defaults that minimise what needs to be
specified, and allowing the use of artifact filters in the configuration of plugins.
How do I prevent including JARs in WEB-INF/lib? I need a "compile only" scope!
The scope you should use for this is provided. This indicates to Maven that the dependency will be provided at run time by its container or the JDK, for example.
Dependencies with this scope will not be passed on transitively, nor will they be bundled in an package such as a WAR, or included in the runtime classpath.
How do I list available plugins?
The "Available Plugins" page lists them, and provides additional information to browse the Maven 2 repository. See http://maven.apache.org/plugins
How do I determine what version of a plugin I am using?
You can use the Maven Help Plugin's describe goal. For example, to find out the version of the install plugin:
Note that you must give the plugin prefix as the argument to plugin, not it's artifact ID.
How can I use Ant tasks in Maven 2?
There are currently 2 alternatives:
Is it possible to create my own directory structure?
Absolutely yes!
By configuring <sourceDirectory>, <resources> and other elements of the <build> section.
In addition, you may need to change the plugin configuration if you are not using plugin defaults for their files/directories.
Where is the source code? I couldn't seem to find a link anywhere on the Maven2 site.
The source code can be found in subversion: http://svn.apache.org/repos/asf/maven/components/trunk.
For more information, see Building Maven 2.0.
Why does Maven compile my test classes but don't run them?
Tests are run by the surefire plugin. The surefire plugin can be configured to run certain test classes and you may have unintentionally done so by specifying a value to $
Unknown macro: {test}
. Check your settings.xml and pom.xml for a property named "test" which would like this:
or
Where are the Maven XSD schemas?
The Maven XSD is located here and the Maven Settings XSD is located here.
Your favorite IDE probably supports XSD schema's for pom.xml and settings.xml editing. You need to specify the following: