facebook

Maven Tips

Find out more about this end-to-end project management tool which has a nearly limitless array of features thanks to its plugin-based nature.  Here you will learn how to:

  • Fix some warnings and interpret errors
  • Install your own JARs into a Maven repository
  • Run “site”

This feature is available in MyEclipse.

1. How to fix the ‘Add JDK’ warning

When working with Maven4MyEclipse for the first time, you might execute a Maven operation that requires a full JDK (as opposed to just a JRE) to run. When that happens, you might get a JDK Warning. If you see this warning, you can click the Maven JDK link to jump directly to the configuration screen where you can set a JDK for Maven to use.


JDK warning

If you already have some JDKs configured (by selecting Window>Preferences from the menu, expanding Java, and selecting Installed JREs) you can select them using the drop-down list, or click the Add button add a new one.


Setting a Maven JDK

If you choose to add a new JDK, it’s as easy as selecting the JDK’s home/install folder; Eclipse fills out the remaining information for you. Click OK, to update the Maven JDK.


Adding a JDK

You shouldn’t have to set this property again, and if Maven should need to use a JDK, it will use the one you have set.


JDK selection

2. How to interpret the ‘No JAR’ or ‘Missing artifact’ errors

In some cases, it is possible to add an unresolved dependency to  your project using Maven4MyEclipse that doesn’t exist in the remote Maven repository or your local Maven repository. Add a dependency by right-clicking the Maven project, and selecting Maven4MyEclipse>Add Dependency.


Adding a dependency

If those dependencies cannot be resolved from the local or remote repositories, you get a validation error on your pom.xml file as well as a build failure on your project for the missing artifact required to build the project successfully.

Missing artifact error

When this happens you have two choices:

  • Import the resource into your local repository so it can be resolved (for instructions on how to do this, please see the next section).
  • Remove the broken dependency and add a valid dependency in its place.

In the second case, the project had the following broken dependency:


Broken dependency

The fix is to manually edit the pom.xml file and remove the `<dependency>` tag that contains the broken reference, then add the working dependency. In this case, by adding springframework (the 6th item listed in the image above) instead, and the error resolves. There may be times where trial-and-error are required to determine which references are resolving and which aren’t if you run into this problem.

3. How to install your own JARs into a Maven repository

One of the most powerful and unique features in Maven4MyEclipse is the ability to import JARs directly into the remote repository by way of a wizard.

Select File>Import, expand Maven4MyEclipse, and choose Import Jar to Maven Repository.


Importing a JAR using the Import wizard

Another import method is to select MyEclipse>Utilities>Maven4MyEclipse>Import Jar to Local Repository from the menu.


Importing a JAR from the menu

You then select the JAR you want to import into your repository and enter the appropriate Group Id (a parent package, if you want to think of it that way) and Artifact Id (a specific project package). Select a Version, and click Finish to import the JAR into your repository.


JAR import details

Once a JAR has been imported into the repository, you are free to add it as a Dependency to any other project, and Maven4MyEclipse will resolve it correctly for you.

4. How to run ‘Site’ for generating project status report resources

Maven provides the ability to generate a large number of reports for your projects, including but not limited to CheckStyle reports, Code Coverage reports, Code Dependency reports, PMD/Code Violation reports and more. Generating reports for your project is typically done by adding the appropriate set of plugins and parameters for those plugins to the reporting portion of your pom.xml file.

Below is an example (please adjust/change to fit your needs) of a reporting portion that you can copy and paste into your pom.xml right after the dependencies closing tag to have Maven generate site reporting for you (when running the site goal):

<reporting> 
  <plugins> 
	<plugin> 
	  <groupId>org.codehaus.mojo</groupId> 
	  <artifactId>cobertura-maven-plugin</artifactId> 
	</plugin> 
	<plugin> 
	  <groupId>org.apache.maven.plugins</groupId> 
	  <artifactId>maven-surefire-report-plugin</artifactId>
	</plugin> 
	<plugin> 
	  <groupId>org.apache.maven.plugins</groupId> 
	  <artifactId>maven-javadoc-plugin</artifactId> 
	</plugin> 
	<plugin> 
	  <groupId>org.apache.maven.plugins</groupId> 
		<artifactId> 
			maven-project-info-reports-plugin 
		</artifactId> 
		<reportSets> 
			<reportSet> 
				<reports> 
				<report>summary</report> 
				  <report>dependencies</report> 
				  <report>project-team</report> 
				</reports> 
			</reportSet> 
		</reportSets> 
	</plugin> 
	<plugin> 
	  <groupId>org.codehaus.mojo</groupId> 
		<artifactId>jxr-maven-plugin</artifactId> 
	</plugin> 
	<plugin> 
	  <groupId>org.apache.maven.plugins</groupId> 
		<artifactId>maven-surefire-report-plugin</artifactId>
		<version>2.4.2</version> 
	</plugin> 
	<plugin> 
	  <artifactId>maven-clover-plugin</artifactId> 
	</plugin> 
	<plugin> 
	  <groupId>org.apache.maven.plugins</groupId> 
	  <artifactId>maven-pmd-plugin</artifactId> 
		<configuration> 
		  <targetjdk>1.5</targetjdk> 
		  <rulesets> 
		     <ruleset>/rulesets/basic.xml</ruleset> 
		     <ruleset>/rulesets/controversial.xml</ruleset>  		  
		  </rulesets> 
		  <format>xml</format> 
		  <linkXref>true</linkXref> 
		  <sourceEncoding>utf-8</sourceEncoding> 
		  <minimumTokens>100</minimumTokens> 
		</configuration> 
	</plugin> 
	<plugin> 
	  <groupId>org.apache.maven.plugins</groupId> 
	  <artifactId>maven-checkstyle-plugin</artifactId> 
	</plugin> 
	<plugin> 
	  <groupId>org.codehaus.mojo</groupId> 
	  <artifactId>jdepend-maven-plugin</artifactId> 
	</plugin> 
</plugins> 
</reporting> 
<developers> 
	<developer> 
		<id>sally</id> 
		<name>Sally Serena</name> 
		<email>sally.serena@mycompany.com</email> 
		<roles> 
			<role>Developer</role> 
		</roles> 
		<organization>My Great Company</organization> 
	</developer> 
	<developer> 
		<id>micky</id> 
		<name>Micky Mango</name> 
		<email>micky.mango@mycompany.com</email> 
		<roles> 
			<role>Developer</role> 
		</roles> 
		<organization>My Great Company</organization> 
	</developer> 
</developers> 
<contributors> 
	<contributor> 
		<name>Jerry Jacobson</name> 
		<email>Jerry.Jacobsen@mycompany.com.com</email> 
		<roles> 
			<role>Management Represented</role> 
		</roles> 
	</contributor> 
</contributors>