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.

Users may also list questions here that they would like answered. So this page can serve as a collection of questions that users would like answered. Please put unanswered questions at the bottom. Please follow the format that is being used because it will help in our automated exaction of material which can then be incorporated into the main site.

Try running with -U - this will force an update check on all plugins. This is often necessary if upgrading Maven from a pre-beta release.

If the problem still persists you may seek help from the Maven user list, browse archived discussions, or log a ticket describing your problem if you think you have found a bug. Tickets could also be issued for feature enhancement requests, and other tasks.

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).

This command installs the jar in your local repository with the generated generic pom.

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.

This command will install the file in your local repository along with your customed pom.

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.

Where is the other plugin?

If you cannot find a certain plugin, you may want to take a look on the following sites.

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.

What is the difference between Maven and Ivy?

How do I get a plug-in's dependencies from a Mojo?

How do I get the project's sources from a Mojo?

Does the v4.0.0 POM include a <versions/> element?

The POM is meant to be current state, not history. We actually only record the versions in the repository, and if the SCM tag is populated in the <scm> section of the POM for each released version you can reconstruct the information.

There were other issues with putting history in the POM: forgetting to add it, getting the right level of information when you work on multiple branches, and similar things.

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. Then you don't need to use the Sink at all.

How do I prevent verification warnings from 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 is shown.

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 Cygwin if you are using a windows machine) that generates sha1sum for all jar, xml and pom files contained in the directory where it is executed:

The script above has been tested on Cygwin and is provided as is and with no guarantee.

This means that the parameter you are overriding in your pom.xml is read-only. Hence, it is not possible to override this parameter.

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.

Can I define the antrun plugin to be executed on demand like "mvn antrun:run"?

This isn't actually possible with the plugin, unless perhaps you do this:

put everything in a top level configuration of the plugin

pass in a variable from the command line, eg -Dtarget=foo antrun:run

execute the appropriate target in the script based on the variable

Ideally, you would write a plugin for these goals (Ant support for
plugins will be available soon, currently you must write them in java
or beanshell).

How do I properly populate variables, when extending a mojo from another plugin?

The field metadata when creating plugins is read from source files, so is not available when the original source is not. The metadata is available in the plugin in META-INF/maven/plugin.xml, but at this point there is no way to incorporate it when building a new plugin.

We currently recommend building your plug-ins using composition instead of inheritence.

How do I integrate static (x)html into my Maven site?

Create your site.xml and put it in ${basedir}/src/site. An example below:

Link the static pages by modifying the <menu> section, create items and map it with the filename of the static pages.

How do I specify that all web modules will inherit the group's common files from a parent web module?

maven-war-plugin 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.

How do I determine which POM contains missing transitive dependency?

run "mvn -X"

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.

How do I determine the stale resources in a Mojo to avoid reprocessing them?

This can be done using the following piece of code:

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:

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:

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:

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.

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).

How do I deploy my binary during the deploy phase?

Then run "mvn deploy".

How do I add main class in a generated jar's manifest?

Configure the maven-jar-plugin and add your main class.

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:

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.

How do I convert my <reports> from Maven 1 to Maven 2?

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

You may now able to pass parameter values to the command line.

"mvn -Dexpression.name=value install"

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:

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.

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

The snapshot version of the plugin is not updated in the snapshot repo, What should I do to update my copy of the plugin?

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.

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.

Handle special characters in site

If using xmlbuddy with eclipse to edit xdoc files set the encoding
Honor encoding
Default to ISO-8859-1

Configuration in pom

On the solaris machine
In $HOME/.profile

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

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

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:

Now, to specify a different output directory at runtime simply use the directory property as a mvn command line parameter;

This will send the build's output files to the ${basedir}/tmp directory.

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.

How do I change the default remote repository?

Define in your POM a repository with "central" as the repository id.

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.

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:

For the second solution:
Add the following at the top level POM:

And in directory A/B/, add an extra parent POM and add the following:

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:

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.

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.

This would display all the goals and descriptions of the parameters used by maven-eclipse-plugin.

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.

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.

Where to find the source code for org.apache.maven.model package?

The source for the model package is generated by modello. From your maven-model source, build it and you should able to see tha java files inside /target/generated-sources directory.

List of available maven 2 mirrors.

Here is the list of available mirrors you can use, just use one of the following mirror entries in your settings.xml

How does maven 2 implement reproducibility?

Add the exact versions of plugins into your pluginDepenencies (make use of the release plugin)

Make use of ibiblio for your libraries. This should always be the case for jars. (The group is working on stabilising metadata and techniques for locking it down even if it changes. An internal repository mirror that doesn't fetch updates (only new) is recommended for true reproducibility.)

Unsupported Protocol Error when deploying a 3rd party jar. What should I do?

How to make a war artifact as a dependency?

When specifying a war as dependency, make sure that you have set the <type> to war.

How can I change the default location of the generated jar when I command "mvn package"?

By default, the location of the generated jar is in ${project.build.directory} or in your target directory.
We can change this by configuring the outputDirectory of maven-jar-plugin.

How can I disable the timestamp appended in my deployed artifact?

When your deployed artifact is appended by timestamps it means that the artifact version is still in SNAPSHOT,
meaning it is still in the state of development. There are some ways the append process of the timestamp,

1. Change the version of your artifact.
For example, From 1.0-SNAPSHOT to 1.0

How do I filter which classes should be put inside the packaged jar?

All compiled classes are always put into the packaged jar. However, you can configure the compiler plugin to exclude compiling some of the java sources using the compiler parameter excludes as follows:

How do I install the package generated by the assembly plugin to be installed in the local repository?

Use the assembly plugin goal assembly:attach to install the generated package into the local repository. However, this feature is still in SVN. Please see Guide to Testing Development Plugins for more info on how to use it.

Is it possible to use HashMap as configurable parameter in a plugin? How do I configure that in pom.xml?

Yes. Its possible to use a HashMap field as a parameter in your plugin. To use it, your pom configuration should look like this:

How do I setup the classpath of my antrun plugin to use the classpath from maven?

The maven classpaths are available as ant references when running your ant script. The ant reference names and some examples can be found here: maven-antrun-plugin

Is there a way to read and examine the contents of a pom.xml file from inside an application?

Yes. You can use the org/apache/maven/model/io/xpp3/MavenXpp3Reader class from maven model to read a pom.

Which plugins have StarTeam (SCM) support? How do they differ?

maven-scm-plugin and maven-release-plugin support via maven-scm's API and maven-scm-provider-starteam. Release plugin is used to cut a new release of your project (label, build, assembly, deploy, etc.). SCM plugin, on the other hand, is for scm tasks.

Is there a way to use the deploy phase to perform some tasks without maven trying to install the artifact to a maven repository?

If you run 'mvn deploy', the 'maven-deploy-plugin' kicks in. There's no flag that tells it not to upload the file. So you'd have to make a new lifecycle mapping/packaging for each <type> of artifact in your project. There's no way to 'delete' mojo's from the default lifecycle. What you could do is specify the remote repo as file:///tmp or something. Usually people want to 'upload' a war to the tomcat webapps dir, also known as deploying. That kind of deploying is not something m2 has a phase for.

What you can do is create a profile in the pom (or super pom), and add a task/mojo to the 'install' phase. For instance, you can have the antrun plugin copy the artifact to the tomcat directory (its location specified in settings.xml). The profile is named 'dev', so whenever you want to deploy a war, you just type 'mvn install -Pdev'. Don't bind to the deploy phase, but to the install or package phase.

Repository precedence

The repositories are searched through based in the order they are defined in your pom. The inherited repositories are always searched last.
Note: You don't have to define the central repo (i.e. ibiblio).

Is it possible to exclude a package from the generated jar file?

You can configure maven-compiler-plugin to exclude your unwanted packages or files to be compiled in the first place. But you will not be able to prevent javac to compile those files if they are referenced by other packages within the source tree. To prevent that, you will need to use antrun plugin ( or write your own custom plugin), bind it to compile phase, and remove unwanted classes in ${project.build.directory}/classes. If possible, just move those pacakges/files to another source tree to become another project.

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?

If yu don't want to change your system JAVA_HOME, set it in maven script instead.

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?

The release:prepare requires the project to be released be a snapshot because it follows the maven development process where: - during development, everyone works on snapshots

at release time, the snapshot got changed to release version, checked back into SCM, labelled and then built.

the version is then incremented with snapshot and checked into SCM again.

It is possible to do a release:prepare from a parent project, but both the parent project and its sub-project must be in snapshot states.

When performing release:prepare in a sub project, the parent cannot be in snapshot state. The key here is that we want to be able to reproduce the build with a label. Any snapshot state from parent or dependencies will prevent that from happening.

How can I create an archetype with resources mapped to the class files directory?

Specify the resources to be sources as shown below:

How do I add a description to the welcome page of the generated site when I execute mvn site?

Fille up the <description> in the pom.xml as shown below:

What does (f) and (s) debug output mean?

(f) is for field injection while (s) is for setter injection.

Is there a preferred way to communicate dependencies in documentation?

Same format used in Maven error reporting:

groupId:artifactId:version

This should be easy to understand by Maven users.

Are there any recommendations on how to handle dependencies, which aren't always required?

How to resolve problems with jtaxxx.jar?

One trick is to use apache gerinomo jars instead of installing everything manually.

How not to include all jar files from parent pom?

Use the right scope. If you don't want them to be included, specify the scope of your dependency as provided.

How to make Continuum work in service mode when an Error 1067 is reported?

When using WinXP, Continuum works in command line but not in service mode and reports an "Error 1067". This is due to the system path including spaces (e.g. "c:Program Files"). To fix this remove the %PATH% references in wrapper.conf.

Which part in pom.xml the javadoc plugin should be configured?

It can be done in the plugins section of the pom or in the plugins section of the report section in the pom.

Generally, you should configure it in the reporting section. 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 (e.g. 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 (e.g., some plugins have a fail build option).

What would it take for the MOJO one to get out of the sandbox?

A full release, with active developers.

Using xdoclet, how come "<fileset dir="src/main"><include name="*/beans/*/*Bean.java"/></fileset>" does not work?

For an example, let's say you have a Java source at src/main/java/com/junk/JunkBean.java. For it to compile correctly, it needs to have a "package com.junk;" in it. When XDoclet walks the source starting at "src/main", it find a source file that identifies itself as being in package "com.junk" but it findsthe source in package "java.com.junk". Since the two don't match, XDoclet assumes that there is a serious problem with the source file and ignores it.

How do I indicate array types in a MOJO configuration?

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?

How will the plugin be licensed? Is it intended to just be a binary distribution or will the source be available? Where will be the documentation be? How will people find out about it?
I think your choice is probably influenced by these questions. One option, of course, is to propose it to mojo.codehaus.org if you want to and can share the code.

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 there a setting for testing, where I can add a directory to the classpath, which will allow the tests to access the files?

How can I stop this "WARNING While downloading artifactId-artifactId-version This artifact has been relocated to groupId-artifactId-version"?

It's probably because some other dependency has specified the dependency on artifactId:artifactId. It will only go away when that declaration is fixed in that POM.

I would like clarification on what version of the JDK is required for m2 – particularly with respect to creating Plugins.

1.4 is required to run m2 there're problems when using 1.5 features in plugins. People tried and failed because qdox (used for some mojo stuff doesn't support new 1.5 language)

i'm wondering what a "snapshot" actually is.

A snapshot is a development version. e.g, 2.0-SNAPSHOT is thestill-in-development future 2.0.If you want to use a snapshot, just use <version> , e.g. <version>2.0-SNAPSHOT</version> . But first you must ensure that you have access to the repository containing this version.

Is it possible that if I do mvn eclipse eclipse goal that my project would get disconnected from the subversion repository?

1.4 is required to run m2 there're problems when using 1.5 features in plugins. People tried and failed because qdox (used for some mojo stuff doesn't support new 1.5 language)

Does it matter if the project's directory name is not the same as the artifactId?

It does not really matter. It'll work, some defaults might have to be overridden (eg SCM inheritance, though that's hopefully going to change), and the parent path if not.

Unanswered Questions

Where can I find a listing of the available variable references that could be use during site generation?

How do I run a shell script from inside a Mojo?

Will the release plug-in resolve all my SNAPSHOT dependencies?

How to copy files from local repo to remote repository?

Where should sql, dtds, test data and generated docs go?

Is there a way for plugin goals to be aware of the phase they are being executed on?

When you have a project using a code generator plugin, how can we add the generated sources in the list of eclipse source directory?

How do I tell maven which version of ant I want it to call?

How do I display special characters (i.e. copyright symbol, latin-1) with APT?

Specific [Unanswered] Errors - Need more information

I've got my plugin pom setup to build everything and construct the final zip file. The issue I'm trying to wrap my brain around is keeping my feature.xml and site.xml files up to date with the correct version info. Since I can't use versions like 1.0.0-SNAPSHOT in my plugin, I have to munge the plugins pom version into something like 1.0.0.v${DATETIME} and insert that into the plugins descriptor (plugin.xml). Since the version in the plugin.xml changes I have to update the plugin entries in the feature descriptor (feature.xml), rev the feature and update the site.xml with the new feature version. Just curious to see if anyone else out there is struggling with these same issues and what if any solutions/band-aids have been implemented

jdcasey

This is more of a user-list type of question. It's going to be an in-depth discussion about designing and/or configuring a suite of plugins for a very specific purpose. This probably isn't a Frequently Asked Question.

Why the FTP Wagon hangs?

jdcasey

Need more information on this. Under what circumstances does this happen? Can the user access the server in another FTP client? Is there a stack trace associated? Do they have a corresponding <server/> section in the settings.xml?

When I run the release:prepare goal I get an authorization failed error. I tried adding the username and password into my pom.xml file and I still get the error. I checked using the command line and my username and password is being cached by subversion. Any ideas?

jdcasey

This is the entry point for a debugging discussion. From here, the user may need to verify that they have the 'svn' command in their path, and that Maven is trying to use subversion with the same username that the user has verified by hand. After that, it depends.

Why am I getting this error when I build my project: "Unable to locate the Javac Compiler"?

jdcasey

We would need to get more information about this user's POM and environment (output of the build would be most valuable) in order to effectively answer this question. Without this context, it is unanswerable.

Why do I get java.lang.NullPointerException while trying to generate site for a project?

jdcasey

Even a simple stacktrace for this user's error would help immensely in debugging this problem. Without specifics, any higher analysis is virtually impossible.