{"id":270,"date":"2010-07-12T04:51:02","date_gmt":"2010-07-12T04:51:02","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/2010\/07\/12\/maven2-step-by-step\/"},"modified":"2021-11-19T10:01:01","modified_gmt":"2021-11-19T10:01:01","slug":"maven2-step-by-step","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/maven2-step-by-step\/","title":{"rendered":"Maven2 Step by Step Guide &#8211; Complete Introduction"},"content":{"rendered":"<div class=\"post-body entry-content\">\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4451\" src=\"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2010\/07\/maven2-step-by-step.png\" alt=\"maven2-step-by-step\" width=\"600\" height=\"400\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2010\/07\/maven2-step-by-step.png 600w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2010\/07\/maven2-step-by-step-300x200.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p><strong>Setting up the application frame<\/strong><\/p>\n<p>The Maven2 documentation is silent about how to set up web application skeletons. The standard archetypes allow you to create a simple standalone, a simple web application (no Java code), and a multi-module project. Presumably, the recommended approach to creating a standard web application (JSP and HTML code for the view, and Java code for the Model and Controller layers) is to create a multi-module project containing a single simple web application and one or more standalone applications for the Model and Controller. However, it is possible to make Maven2 work with a standard web application structure by adding some directories to the skeleton created by the standalone Maven archetype.<\/p>\n<p>The Maven2 <a href=\"http:\/\/maven.apache.org\/guides\/getting-started\/index.html\" target=\"_blank\" rel=\"noopener\"><span style=\"text-decoration: underline;\"><span style=\"color: #de7008;\">Getting started Guide<\/span><\/span><\/a> has some commands for creating skeletons from standard Maven archetypes. To create the skeleton for an application my-app in the com.mycompany.app namespace using a standalone archetype, run this command:<\/p>\n<table class=\"highlighttable\" border=\"0\">\n<tbody>\n<tr>\n<td class=\"linenos\">\n<pre>1<\/pre>\n<\/td>\n<td class=\"code\">\n<div class=\"highlight\">\n<pre><span class=\"gp\"><strong><span style=\"color: #000080;\">$<\/span><\/strong><\/span> mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=my-app<\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>To make a standard web application skeleton from this, add the following directories. The webapps directories is the root of the web applications context, and contains the WEB-INF directory. The resources subdirectory corresponds to the WEB-INF\/classes directory for a web application or the conf\/ or etc\/ directory for a standalone, where all the properties files go. The test\/resources\/ directory is useful for storing test specific properties files.<\/p>\n<table class=\"highlighttable\" border=\"0\">\n<tbody>\n<tr>\n<td class=\"linenos\">\n<pre>1\n2\n3\n4<\/pre>\n<\/td>\n<td class=\"code\">\n<div class=\"highlight\">\n<pre>my-app\/src\/main\/webapps\/\nmy-app\/src\/main\/webapps\/WEB-INF\/\nmy-app\/src\/main\/resources\/\nmy-app\/src\/test\/resources\/<\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Finally, to make a web application out of the standard standalone application, change the value of project.packaging from jar to war in the pom.xml file.<\/p>\n<p><strong>Standard Maven2 Goals<\/strong><\/p>\n<p>Maven2 provides some standard goals which are similar to Ant targets found in most project&#8217;s build.xml files. This helps people familiar with Ant to make a quick transition to using Maven2. They are as follows:<\/p>\n<table class=\"highlighttable\" border=\"0\">\n<tbody>\n<tr>\n<td class=\"linenos\">\n<pre>1\n2\n3\n4\n5\n6<\/pre>\n<\/td>\n<td class=\"code\">\n<div class=\"highlight\">\n<pre>mvn clean - cleans out all Maven2 generated files.\nmvn compile - compiles the Java sources\nmvn test-compile - compiles the Java JUnit test classes.\nmvn test - runs all JUnit tests in the project.\nmvn package - builds the JAR or WAR file for the project.\nmvn install - installs the JAR or WAR file in the local Maven repository.<\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Most of these goals are configured in the super-POM, but if you want to build your application using Java 1.5 (who doesn&#8217;t these days), you will need some additional configuration in your pom.xml, in the project.build.plugins element in your pom.xml.<\/p>\n<table class=\"highlighttable\" border=\"0\">\n<tbody>\n<tr>\n<td class=\"linenos\">\n<pre>1\n2\n3\n4\n5\n6\n7\n8\n9<\/pre>\n<\/td>\n<td class=\"code\">\n<div class=\"highlight\">\n<pre>      <span class=\"c\"><em><span style=\"color: #008800;\">&lt;!-- Java 1.5 compiler plugin --&gt;<\/span><\/em><\/span>\n      <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;plugin&gt;<\/span><\/strong><\/span>\n        <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;groupId&gt;<\/span><\/strong><\/span>org.apache.maven.plugins<span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/groupId&gt;<\/span><\/strong><\/span>\n        <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;artifactId&gt;<\/span><\/strong><\/span>maven-compiler-plugin<span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/artifactId&gt;<\/span><\/strong><\/span>\n        <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;configuration&gt;<\/span><\/strong><\/span>\n          <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;source&gt;<\/span><\/strong><\/span>1.5<span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/source&gt;<\/span><\/strong><\/span>\n          <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;target&gt;<\/span><\/strong><\/span>1.5<span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/target&gt;<\/span><\/strong><\/span>\n        <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/configuration&gt;<\/span><\/strong><\/span>\n      <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/plugin&gt;<\/span><\/strong><\/span><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Generating IDE configuration files<\/strong><\/p>\n<p>Most people work with some kind of IDE, and the IDE must be told where to look for JAR files, Java code, test code, etc. Since this information is already specified in the pom.xml files, Maven2 can generate the IDE artefacts for a large number of popular IDEs in use, such as Eclipse, IDEA and Emacs JDEE. To generate the Eclipse artefacts for your project, run the following command:<\/p>\n<table class=\"highlighttable\" border=\"0\">\n<tbody>\n<tr>\n<td class=\"linenos\">\n<pre>1<\/pre>\n<\/td>\n<td class=\"code\">\n<div class=\"highlight\">\n<pre><span class=\"gp\"><strong><span style=\"color: #000080;\">$<\/span><\/strong><\/span> mvn eclipse:eclipse<\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>You also need to tell Eclipse where to find the your local Maven2 repository (under ~\/.m2\/repository by default). You can do this by setting a global environment variable M2_REPO in the IDE.<\/p>\n<p><strong>Running Jetty in place (webapps)<\/strong><\/p>\n<p>A nice touch is the <a href=\"http:\/\/mojo.codehaus.org\/jetty-maven-plugin\/usage.html\" target=\"_blank\" rel=\"noopener\"><span style=\"text-decoration: underline;\"><span style=\"color: #de7008;\">Maven2 Jetty Plugin<\/span><\/span><\/a>. This starts up a Jetty installation in place in your web application. This is a huge time-saver, since web application development is often an iterative cycle of changing code, deploying to application server, checking a web page and back. Having Jetty running on your web application source enables you to see your changes instantly (or after compiling with changes in Java code). To set it up, you will need to add the following configuration in project.build.plugins in your pom.xml file.<\/p>\n<table class=\"highlighttable\" border=\"0\">\n<tbody>\n<tr>\n<td class=\"linenos\">\n<pre> 1\n 2\n 3\n 4\n 5\n 6\n 7\n 8\n 9\n10\n11\n12\n13\n14\n15<\/pre>\n<\/td>\n<td class=\"code\">\n<div class=\"highlight\">\n<pre>      <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;plugin&gt;<\/span><\/strong><\/span>\n        <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;groupId&gt;<\/span><\/strong><\/span>org.mortbay.jetty<span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/groupId&gt;<\/span><\/strong><\/span>\n        <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;artifactId&gt;<\/span><\/strong><\/span>maven-jetty6-plugin<span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/artifactId&gt;<\/span><\/strong><\/span>\n        <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;configuration&gt;<\/span><\/strong><\/span>\n          <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;scanIntervalSeconds&gt;<\/span><\/strong><\/span>10<span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/scanIntervalSeconds&gt;<\/span><\/strong><\/span>\n        <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/configuration&gt;<\/span><\/strong><\/span>\n        <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;dependencies&gt;<\/span><\/strong><\/span>\n          <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;dependency&gt;<\/span><\/strong><\/span>\n            <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;groupId&gt;<\/span><\/strong><\/span>org.apache.geronimo.specs<span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/groupId&gt;<\/span><\/strong><\/span>\n            <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;artifactId&gt;<\/span><\/strong><\/span>geronimo-j2ee_1.4_spec<span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/artifactId&gt;<\/span><\/strong><\/span>\n            <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;version&gt;<\/span><\/strong><\/span>1.0<span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/version&gt;<\/span><\/strong><\/span>\n            <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;scope&gt;<\/span><\/strong><\/span>provided<span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/scope&gt;<\/span><\/strong><\/span>\n          <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/dependency&gt;<\/span><\/strong><\/span>\n        <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/dependencies&gt;<\/span><\/strong><\/span>\n      <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/plugin&gt;<\/span><\/strong><\/span><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Then start up Jetty with the following command. You should be able to see your web application on your browser at http:\/\/localhost:8080\/my-app.<\/p>\n<table class=\"highlighttable\" border=\"0\">\n<tbody>\n<tr>\n<td class=\"linenos\">\n<pre>1<\/pre>\n<\/td>\n<td class=\"code\">\n<div class=\"highlight\">\n<pre><span class=\"gp\"><strong><span style=\"color: #000080;\">$<\/span><\/strong><\/span> mvn jetty6:run<\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Documentation: The project website<\/strong><\/p>\n<p>I think of documentation as a place to tell the world all about the cool things my project does. However, too many projects skimp on documentation, because of the effort in setting up the infrastructure in place to generate documentation. Maven2 has built in support for generating a project website with all the documentation for your project. Data entered into the pom.xml drives a lot of the reports, such as Mailing List, Issue Management, Source Repository, etc. Maven2 needs to be told which reports to generate in the project.reporting.plugins section of the pom.xml. Details about which pom.xml entries drive which report elements can be found in Resources[2].<\/p>\n<table class=\"highlighttable\" border=\"0\">\n<tbody>\n<tr>\n<td class=\"linenos\">\n<pre> 1\n 2\n 3\n 4\n 5\n 6\n 7\n 8\n 9\n10\n11\n12\n13\n14\n15\n16\n17<\/pre>\n<\/td>\n<td class=\"code\">\n<div class=\"highlight\">\n<pre>      <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;plugin&gt;<\/span><\/strong><\/span>\n        <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;groupId&gt;<\/span><\/strong><\/span>org.apache.maven.plugins<span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/groupId&gt;<\/span><\/strong><\/span>\n        <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;artifactId&gt;<\/span><\/strong><\/span>maven-project-info-reports-plugin<span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/artifactId&gt;<\/span><\/strong><\/span>\n        <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;reportSets&gt;<\/span><\/strong><\/span>\n          <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;reportSet&gt;<\/span><\/strong><\/span>\n            <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;reports&gt;<\/span><\/strong><\/span>\n              <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;report&gt;<\/span><\/strong><\/span>dependencies<span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/report&gt;<\/span><\/strong><\/span>\n              <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;report&gt;<\/span><\/strong><\/span>project-team<span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/report&gt;<\/span><\/strong><\/span>\n              <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;report&gt;<\/span><\/strong><\/span>mailing-list<span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/report&gt;<\/span><\/strong><\/span>\n              <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;report&gt;<\/span><\/strong><\/span>cim<span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/report&gt;<\/span><\/strong><\/span>\n              <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;report&gt;<\/span><\/strong><\/span>issue-tracking<span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/report&gt;<\/span><\/strong><\/span>\n              <span class=\"c\"><em><span style=\"color: #008800;\">&lt;!-- &lt;report&gt;license&lt;\/report&gt; --&gt;<\/span><\/em><\/span>\n              <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;report&gt;<\/span><\/strong><\/span>scm<span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/report&gt;<\/span><\/strong><\/span>\n            <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/reports&gt;<\/span><\/strong><\/span>\n          <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/reportSet&gt;<\/span><\/strong><\/span>\n        <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/reportSets&gt;<\/span><\/strong><\/span>\n      <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/plugin&gt;<\/span><\/strong><\/span><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>You can also create project documentation content, such as User Guides, etc, in a variety of formats, such as <a href=\"http:\/\/www.docbook.org\/\" target=\"_blank\" rel=\"noopener\"><span style=\"text-decoration: underline;\"><span style=\"color: #de7008;\">DocBook<\/span><\/span><\/a> and <a href=\"http:\/\/maven.apache.org\/guides\/mini\/guide-apt-format.html\" target=\"_blank\" rel=\"noopener\"><span style=\"text-decoration: underline;\"><span style=\"color: #de7008;\">APT (Almost Plain Text)<\/span><\/span><\/a>. APT is a wiki-like plain text format which I find very convenient. For FAQ entries, Maven2 supports the FML format.<\/p>\n<p>To set up the project site, create the following directories.<\/p>\n<table class=\"highlighttable\" border=\"0\">\n<tbody>\n<tr>\n<td class=\"linenos\">\n<pre>1\n2\n3\n4\n5<\/pre>\n<\/td>\n<td class=\"code\">\n<div class=\"highlight\">\n<pre>my-app\/src\/site\/apt\/\nmy-app\/src\/site\/fml\/\nmy-app\/src\/site\/resources\/\nmy-app\/src\/site\/resources\/images\/\nmy-app\/src\/site\/site.xml<\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The apt subdirectory should contain the documentation in APT format. The fml subdirectory contains various FAQ source files. The resources subdirectory should contain files and documents that do not need any pre-processing. The files in the apt and fml subdirectory will be pre-processed by the APT and FML processor and be copied to the project site root directory as .html files. The files in the resources subdirectory (including the images\/ subdirectory) will be copied to the project site docroot as is. The site.xml specifies the template for your site, ie what the left and right banners should contain, etc. The site.xml file will reference these HTML files.<\/p>\n<p>To generate the project web site, run the following command. The website will be generated under my-app\/target\/site where you can view it with a browser using the file:\/\/ protocol.<\/p>\n<table class=\"highlighttable\" border=\"0\">\n<tbody>\n<tr>\n<td class=\"linenos\">\n<pre>1<\/pre>\n<\/td>\n<td class=\"code\">\n<div class=\"highlight\">\n<pre><span class=\"gp\"><strong><span style=\"color: #000080;\">$<\/span><\/strong><\/span> mvn site<\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Javadocs<\/strong><\/p>\n<p>The Javadocs plugin needs to be configured explicitly in the project pom.xml in the project.reporting.plugins section.<\/p>\n<table class=\"highlighttable\" border=\"0\">\n<tbody>\n<tr>\n<td class=\"linenos\">\n<pre> 1\n 2\n 3\n 4\n 5\n 6\n 7\n 8\n 9\n10\n11\n12<\/pre>\n<\/td>\n<td class=\"code\">\n<div class=\"highlight\">\n<pre>      <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;plugin&gt;<\/span><\/strong><\/span>\n        <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;groupId&gt;<\/span><\/strong><\/span>org.apache.maven.plugins<span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/groupId&gt;<\/span><\/strong><\/span>\n        <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;artifactId&gt;<\/span><\/strong><\/span>maven-javadoc-plugin<span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/artifactId&gt;<\/span><\/strong><\/span>\n        <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;configuration&gt;<\/span><\/strong><\/span>\n          <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;links&gt;<\/span><\/strong><\/span>\n            <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;link&gt;<\/span><\/strong><\/span>http:\/\/java.sun.com\/j2se\/1.5.0\/docs\/api\/<span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/link&gt;<\/span><\/strong><\/span>\n            <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;link&gt;<\/span><\/strong><\/span>http:\/\/plexus.codehaus.org\/ref\/1.0-alpha-9\/apidocs<span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/link&gt;<\/span><\/strong><\/span>\n            <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;link&gt;<\/span><\/strong><\/span>http:\/\/jakarta.apache.org\/commons\/dbcp\/apidocs\/<span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/link&gt;<\/span><\/strong><\/span>\n            ... other third party libs used by your project ...\n          <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/links&gt;<\/span><\/strong><\/span>\n        <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/configuration&gt;<\/span><\/strong><\/span>\n      <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/plugin&gt;<\/span><\/strong><\/span><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>If the Javadocs plugin has been configured, then mvn site will automatically generate the Javadocs. Otherwise, they can be generated separately using the command:<\/p>\n<table class=\"highlighttable\" border=\"0\">\n<tbody>\n<tr>\n<td class=\"linenos\">\n<pre>1<\/pre>\n<\/td>\n<td class=\"code\">\n<div class=\"highlight\">\n<pre><span class=\"gp\"><strong><span style=\"color: #000080;\">$<\/span><\/strong><\/span> mvn javadoc:javadoc<\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Java Cross Reference (JXR)<\/strong><\/p>\n<p>Another cool plugin is the Code Cross Reference that is created using the JXR plugin. The project code is made displayable with line numbers and syntax highlighting, with links to related code. Almost like having an IDE running on the browser in read-only mode. Though not required for all projects, this is very useful to allow people to review your code without having to download it. To configure it, configure the plugin in the project.reporting.plugins section.<\/p>\n<table class=\"highlighttable\" border=\"0\">\n<tbody>\n<tr>\n<td class=\"linenos\">\n<pre>1\n2\n3\n4<\/pre>\n<\/td>\n<td class=\"code\">\n<div class=\"highlight\">\n<pre>      <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;plugin&gt;<\/span><\/strong><\/span>\n        <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;groupId&gt;<\/span><\/strong><\/span>org.apache.maven.plugins<span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/groupId&gt;<\/span><\/strong><\/span>\n        <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;artifactId&gt;<\/span><\/strong><\/span>maven-jxr-plugin<span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/artifactId&gt;<\/span><\/strong><\/span>\n      <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/plugin&gt;<\/span><\/strong><\/span><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Like the Javadocs goal, this will be run as part of mvn site as well, but can be run separately using the command:<\/p>\n<table class=\"highlighttable\" border=\"0\">\n<tbody>\n<tr>\n<td class=\"linenos\">\n<pre>1<\/pre>\n<\/td>\n<td class=\"code\">\n<div class=\"highlight\">\n<pre>mvn jxr:jxr<\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Code Style (Checkstyle)<\/strong><\/p>\n<p>I chose <a href=\"http:\/\/checkstyle.sourceforge.net\/\" target=\"_blank\" rel=\"noopener\"><span style=\"text-decoration: underline;\"><span style=\"color: #de7008;\">Checkstyle<\/span><\/span><\/a> because I am familiar with it, but I think Maven2 supports other code style checkers too. I use the default Maven code style, since this is likely to become the most popular code style as more and more people embrace Maven2, but this setting can be overriden to use Sun&#8217;s code style or some other style preferred by your corporation. To configure it (with default Maven code style), we need the following configuration in project.reporting.plugins in the pom.xml file.<\/p>\n<table class=\"highlighttable\" border=\"0\">\n<tbody>\n<tr>\n<td class=\"linenos\">\n<pre>1\n2\n3\n4\n5\n6\n7<\/pre>\n<\/td>\n<td class=\"code\">\n<div class=\"highlight\">\n<pre>      <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;plugin&gt;<\/span><\/strong><\/span>\n        <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;groupId&gt;<\/span><\/strong><\/span>org.apache.maven.plugins<span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/groupId&gt;<\/span><\/strong><\/span>\n        <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;artifactId&gt;<\/span><\/strong><\/span>maven-checkstyle-plugin<span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/artifactId&gt;<\/span><\/strong><\/span>\n        <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;configuration&gt;<\/span><\/strong><\/span>\n          <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;configLocation&gt;<\/span><\/strong><\/span>config\/maven_checks.xml<span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/configLocation&gt;<\/span><\/strong><\/span>\n        <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/configuration&gt;<\/span><\/strong><\/span>\n      <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/plugin&gt;<\/span><\/strong><\/span><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>As before, once configured, the report is run as part of the mvn site command, but can be run separately using the command:<\/p>\n<table class=\"highlighttable\" border=\"0\">\n<tbody>\n<tr>\n<td class=\"linenos\">\n<pre>1<\/pre>\n<\/td>\n<td class=\"code\">\n<div class=\"highlight\">\n<pre><span class=\"gp\"><strong><span style=\"color: #000080;\">$<\/span><\/strong><\/span> mvn checkstyle:checkstyle<\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Unit Test Coverage (Cobertura)<\/strong><\/p>\n<p><a href=\"http:\/\/www.cenqua.com\/clover\/\" target=\"_blank\" rel=\"noopener\"><span style=\"text-decoration: underline;\"><span style=\"color: #de7008;\">Clover<\/span><\/span><\/a> is the most popular tool for checking on Unit test coverage, and Maven2 provides a plugin for that. However, Clover is commercial software and costs money. A free, open-source alternative is <a href=\"http:\/\/cobertura.sourceforge.net\/\" target=\"_blank\" rel=\"noopener\"><span style=\"text-decoration: underline;\"><span style=\"color: #de7008;\">Cobertura<\/span><\/span><\/a>. Maven2 provides a <a href=\"http:\/\/maven-plugins.sourceforge.net\/maven-cobertura-plugin\/\" target=\"_blank\" rel=\"noopener\"><span style=\"text-decoration: underline;\"><span style=\"color: #de7008;\">Cobertura plugin<\/span><\/span><\/a> as well. To configure this plugin, add the following XML to project.reporting.plugins section in the pom.xml.<\/p>\n<table class=\"highlighttable\" border=\"0\">\n<tbody>\n<tr>\n<td class=\"linenos\">\n<pre> 1\n 2\n 3\n 4\n 5\n 6\n 7\n 8\n 9\n10\n11\n12\n13\n14\n15<\/pre>\n<\/td>\n<td class=\"code\">\n<div class=\"highlight\">\n<pre>      <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;plugin&gt;<\/span><\/strong><\/span>\n        <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;groupId&gt;<\/span><\/strong><\/span>org.codehaus.mojo<span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/groupId&gt;<\/span><\/strong><\/span>\n        <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;artifactId&gt;<\/span><\/strong><\/span>cobertura-maven-plugin<span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/artifactId&gt;<\/span><\/strong><\/span>\n        <span class=\"c\"><em><span style=\"color: #008800;\">&lt;!--<\/span><\/em><\/span>\n<span class=\"c\"><em><span style=\"color: #008800;\">        &lt;executions&gt;<\/span><\/em><\/span>\n<span class=\"c\"><em><span style=\"color: #008800;\">          &lt;execution&gt;<\/span><\/em><\/span>\n<span class=\"c\"><em><span style=\"color: #008800;\">            &lt;id&gt;clean&lt;\/id&gt;<\/span><\/em><\/span>\n<span class=\"c\"><em><span style=\"color: #008800;\">            &lt;phase&gt;clean&lt;\/phase&gt;<\/span><\/em><\/span>\n<span class=\"c\"><em><span style=\"color: #008800;\">            &lt;goals&gt;<\/span><\/em><\/span>\n<span class=\"c\"><em><span style=\"color: #008800;\">              &lt;goal&gt;clean&lt;\/goal&gt;<\/span><\/em><\/span>\n<span class=\"c\"><em><span style=\"color: #008800;\">            &lt;\/goals&gt;<\/span><\/em><\/span>\n<span class=\"c\"><em><span style=\"color: #008800;\">          &lt;\/execution&gt;<\/span><\/em><\/span>\n<span class=\"c\"><em><span style=\"color: #008800;\">        &lt;\/executions&gt;<\/span><\/em><\/span>\n<span class=\"c\"><em><span style=\"color: #008800;\">        --&gt;<\/span><\/em><\/span>\n      <span class=\"nt\"><strong><span style=\"color: #008000;\">&lt;\/plugin&gt;<\/span><\/strong><\/span><\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The plugin can be run manually using the command:<\/p>\n<table class=\"highlighttable\" border=\"0\">\n<tbody>\n<tr>\n<td class=\"linenos\">\n<pre>1<\/pre>\n<\/td>\n<td class=\"code\">\n<div class=\"highlight\">\n<pre><span class=\"gp\"><strong><span style=\"color: #000080;\">$<\/span><\/strong><\/span> mvn cobertura:cobertura<\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The plugin leaves a cobertura.ser file in the project root directory, which can be removed using mvn clean. There was a suggestion to automate this by creating an executions subelement under the plugin declaration, but I could not get it to work &#8211; the parser complained about invalid tags, so I commented it out (in the above XML snippet). If anyone knows what I did wrong, please let me know.<\/p>\n<p><strong>Deploying files to other locations<\/strong><\/p>\n<p>I dont know much about this, except that it involves using the Maven2 Wagon Plugin. The plugin supports a wide variety of transport formats. I will post more information about this as I find it. If anyone has some information about using Wagon, would appreciate your posting it here or pointing to links with the information.<\/p>\n<p>So thats basically all I have for now. Hopefully, this article will help kickstart Maven2 adoption in your new projects. Personally, I have used Ant for over 6 years now, and I was justifiably sceptical about switching new development to Maven2. However, I have had good success with Maven2 so far, and I am quite impressed with its range of capabilities in terms of integration with other tools and the services it provides to the developer.<\/p>\n<p><strong>Resources<\/strong><\/p>\n<ul>\n<li><a href=\"http:\/\/www.javaworld.com\/javaworld\/jw-05-2006\/jw-0529-maven.html\" target=\"_blank\" rel=\"noopener\"><span style=\"text-decoration: underline;\"><span style=\"color: #de7008;\">The Maven 2 POM demystified<\/span><\/span><\/a> &#8211; I have restructured my template pom.xml according to this article, and it helps a lot in understanding the POM.<\/li>\n<li><a href=\"http:\/\/www.javaworld.com\/javaworld\/jw-02-2006\/jw-0227-maven.html\" target=\"_blank\" rel=\"noopener\"><span style=\"text-decoration: underline;\"><span style=\"color: #de7008;\">Get the most out of Maven2 site generation<\/span><\/span><\/a> &#8211;&nbsp;Much useful information about what elements to populate to produce&nbsp;clear Maven2 project reports.<\/li>\n<li><a href=\"http:\/\/maven.apache.org\/maven-v4_0_0.xsd\" target=\"_blank\" rel=\"noopener\"><span style=\"text-decoration: underline;\"><span style=\"color: #de7008;\">The Maven2 Schema<\/span><\/span><\/a> &#8211; Its hard to figure out what element goes where without examples. The XSD is very detailed and provides good information.<\/li>\n<li><a href=\"http:\/\/www.mergere.com\/m2book_download.jsp\" target=\"_blank\" rel=\"noopener\"><span style=\"text-decoration: underline;\"><span style=\"color: #de7008;\">Better Builds with Maven<\/span><\/span><\/a> &#8211; if you haven&#8217;t already downloaded this free e-book, you should. This is the only book I know of which talks about Maven2, so if you are working with Maven2, you should definitely download and read it.<\/li>\n<li><a href=\"http:\/\/www.amazon.com\/gp\/product\/0596007507\" target=\"_blank\" rel=\"noopener\"><span style=\"text-decoration: underline;\"><span style=\"color: #de7008;\">Maven : A Developer&#8217;s Notebook<\/span><\/span><\/a> &#8211; covers details of the FML format used for generating FAQ entries.<\/li>\n<\/ul>\n<\/div>\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_48720\"><figure class=\"wp-block-embed wp-block-embed-youtube is-type-video is-provider-youtube epyt-figure\"><div class=\"wp-block-embed__wrapper\"><iframe loading=\"lazy\"  id=\"_ytid_57595\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_48720\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><\/div><\/figure><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Setting up the application frame The Maven2 documentation is silent about how to set up web application skeletons. The standard archetypes allow you to create a simple standalone, a simple web application (no Java code), and a multi-module project. Presumably, the recommended approach to creating a standard web application (JSP and HTML code for the&#8230;<\/p>\n","protected":false},"author":1,"featured_media":4451,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[29],"tags":[4325,161,4321,4323,4317,4319,4320,4322,359,4318,4324],"class_list":["post-270","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-maven","tag-about-maven2","tag-maven","tag-maven-2-introduction","tag-maven-2-tutorial","tag-maven2","tag-maven2-documentation","tag-maven2-getting-started-guide","tag-maven2-guide","tag-overview","tag-step-by-step","tag-what-is-maven-2"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/270","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=270"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/270\/revisions"}],"predecessor-version":[{"id":25864,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/270\/revisions\/25864"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/4451"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=270"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=270"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=270"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}