<?xml version="1.0"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>myorg.myproject</groupId>
<artifactId>ex1</artifactId>
<name>My First Simple Project</name>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.13</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>> find . -type f ./src/main/java/myorg/mypackage/ex1/App.java ./src/test/java/myorg/mypackage/ex1/AppTest.java ./src/test/resources/log4j.xml ./build.properties ./build.xml ./pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">$ mvn package [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building My First Simple Project 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ ex1 --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory C:\jhu\784\jboss6\solutions\ex1\src\main\resources [INFO] [INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ ex1 --- [INFO] Compiling 1 source file to C:\jhu\784\jboss6\solutions\ex1\target\classes [INFO] [INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ ex1 --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ ex1 --- [INFO] Compiling 1 source file to C:\jhu\784\jboss6\solutions\ex1\target\test-classes [INFO] [INFO] --- maven-surefire-plugin:2.5:test (default-test) @ ex1 --- [INFO] Surefire report directory: C:\jhu\784\jboss6\solutions\ex1\target\surefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running myorg.mypackage.ex1.AppTest INFO 02-02 11:31:53,487 (AppTest.java:testApp:26) -testApp DEBUG 02-02 11:31:53,487 (App.java:returnOne:11) -Here's One! Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.234 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ ex1 --- [INFO] Building jar: C:\jhu\784\jboss6\solutions\ex1\target\ex1-1.0-SNAPSHOT.jar [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 3.375s [INFO] Finished at: Wed Feb 02 11:31:53 EST 2011 [INFO] Final Memory: 9M/21M [INFO] ------------------------------------------------------------------------ [WARNING] The requested profile "hsql" could not be activated because it does not exist.
> find . -type f ./src/main/java/myorg/mypackage/ex1/App.java ./src/test/java/myorg/mypackage/ex1/AppTest.java ./src/test/resources/log4j.xml ./build.properties ./build.xml ./target/classes/myorg/mypackage/ex1/App.class ./target/test-classes/log4j.xml ./target/test-classes/myorg/mypackage/ex1/AppTest.class ./target/log4j-out.txt ./target/surefire-reports/myorg.mypackage.ex1.AppTest.txt ./target/surefire-reports/TEST-myorg.mypackage.ex1.AppTest.xml ./target/exported-pom.xml ./target/ex1-1.0-SNAPSHOT.jar ./pom.xml
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties><?xml version="1.0"?>
<html>
<head>
<title>My First Project</title>
</head>
<body>
<section><h1>My First Project</h1></section>
<p/>
This is my first project. Take a look at
<p/>
<ul>
<li>this ....</li>
<li>that ....</li>
<li>or <a href="./index.html">go home</a></li>
</ul>
</section>
</body>
</html><?xml version="1.0" encoding="ISO-8859-1"?>
<project name="${project.name}">
<body>
<menu name="Content">
<item name="README" href="README.html"/>
</menu>
</body>
</project>> find . -type f ./src/main/java/myorg/mypackage/ex1/App.java ./src/test/java/myorg/mypackage/ex1/AppTest.java ./src/test/resources/log4j.xml ./src/site/resources/README.html ./src/site/site.xml ./build.properties ./build.xml ./pom.xml
> mvn site [INFO] Scanning for projects... [INFO] ...
> find ./target -type f ./target/site/integration.html ./target/site/dependencies.html ./target/site/issue-tracking.html ./target/site/license.html ./target/site/mail-lists.html ./target/site/index.html ./target/site/project-summary.html ./target/site/source-repository.html ./target/site/team-list.html ./target/site/project-info.html ./target/site/css/maven-theme.css ./target/site/css/maven-base.css ./target/site/css/print.css ./target/site/images/external.png ./target/site/README.html
<build>
...
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<version>2.5</version>
</plugin>
</plugins>
</pluginManagement>
...
</build> <reporting>
<plugins>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<version>2.8.1</version>
<configuration>
<detectLinks/>
<show>private</show>
<source>1.6</source>
<links>
<link>http://download.oracle.com/javaee/6/api/</link>
<link>http://download.oracle.com/javase/6/docs/api/</link>
</links>
</configuration>
</plugin>
</plugins>
</reporting><?xml version="1.0" encoding="ISO-8859-1"?>
<project name="${project.name}">
<body>
<menu name="Content">
<item name="README" href="README.html"/>
</menu>
<menu ref="reports"/>
</body>
</project><?xml version="1.0"?>
<settings xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
</settings> <!-- this overrides the default $HOME/.m2/repository location. -->
<localRepository>c:/jhu/repository</localRepository> <profile>
<id>debugger</id>
<!-- this should only be activated when performing interactive
debugging -->
<activation>
<property>
<name>debugger</name>
</property>
</activation>
<properties>
<surefire.argLine>-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -Xnoagent -Djava.compiler=NONE</surefire.argLine>
</properties>
</profile> <dependency>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>1.1</version>
<scope>provided</scope>
</dependency>> mvn package [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building My First Simple Project 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ Downloading: http://webdev.apl.jhu.edu/~jcs/maven2/foo/bar/1.1/bar-1.1.pom Downloading: http://webdev.apl.jhu.edu/~jcs/maven2-snapshot/foo/bar/1.1/bar-1.1.pom Downloading: http://repo1.maven.org/maven2/foo/bar/1.1/bar-1.1.pom [WARNING] The POM for foo:bar:jar:1.1 is missing, no dependency information available Downloading: http://webdev.apl.jhu.edu/~jcs/maven2/foo/bar/1.1/bar-1.1.jar Downloading: http://webdev.apl.jhu.edu/~jcs/maven2-snapshot/foo/bar/1.1/bar-1.1.jar Downloading: http://repo1.maven.org/maven2/foo/bar/1.1/bar-1.1.jar [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.437s [INFO] Finished at: Wed Feb 02 12:20:51 EST 2011 [INFO] Final Memory: 2M/15M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal on project ex1: Could not resolve dependencies for project myorg.myproject:ex1:jar:1.0-SNAPSHOT: Could not fi nd artifact foo:bar:jar:1.1 in webdev-baseline (http://webdev.apl.jhu.edu/~jcs/maven2) -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
$ mvn install:install-file -DgroupId=foo -DartifactId=bar \ > -Dversion=1.1 -Dpackaging=jar -Dfile=bar.jar \ > -DgeneratePom=true [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building My First Simple Project 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-install-plugin:2.3.1:install-file (default-cli) @ ex1 --- [INFO] Installing C:\jhu\784\jboss6\solutions\ex1\bar.jar to c:\jhu\repository\foo\bar\1.1\bar-1.1.jar [INFO] Installing C:\Documents and Settings\jcstaff\mvninstall2771571397162981253.pom to c:\jhu\repository\foo\bar\1.1\bar-1.1.pom [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.032s [INFO] Finished at: Wed Feb 02 12:25:12 EST 2011 [INFO] Final Memory: 2M/15M [INFO] ------------------------------------------------------------------------
$ find c:/jhu/repository/foo/ -type f
c:/jhu/repository/foo/bar/1.1/bar-1.1.jar
c:/jhu/repository/foo/bar/1.1/bar-1.1.jar.lastUpdated
c:/jhu/repository/foo/bar/1.1/bar-1.1.pom
c:/jhu/repository/foo/bar/1.1/bar-1.1.pom.lastUpdated
c:/jhu/repository/foo/bar/1.1/_maven.repositories
c:/jhu/repository/foo/bar/maven-metadata-local.xml
$ more c:/jhu/repository/foo/bar/1.1/bar-1.1.pom
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/P
OM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>1.1</version>
<description>POM was created from install:install-file</description>
</project>This is useful to determine what all the delegation summed up to.
$ mvn help:effective-pom
...
<!-- ====================================================================== -->
<!-- -->
<!-- Effective POM for project 'myorg.myproject:ex1:jar:1.0-SNAPSHOT' -->
<!-- -->
<!-- ====================================================================== -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://w
ache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>myorg.myproject</groupId>
<artifactId>ex1</artifactId>
<version>1.0-SNAPSHOT</version>
<name>My First Simple Project</name>
<properties>
<jboss.home>c:/apps/jboss-6.1.0.Final</jboss.home>
<jboss.host>localhost</jboss.host>
<jboss.password>password</jboss.password>
<jboss.protocol>http</jboss.protocol>
<jboss.server>ejava-jboss6</jboss.server>
<jboss.servlet.port>8080</jboss.servlet.port>
<jboss.user>admin</jboss.user>
<m2.repo>c:/jhu/repository</m2.repo>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>There are various ways to implement local properties that do the work of the global settings.xml. To get the net result, use the following
mvn help:effective-settings
...
<settings xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.a
pache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
<localRepository xmlns="http://maven.apache.org/SETTINGS/1.1.0">c:\jhu\repository</localRepository>
<activeProfiles xmlns="http://maven.apache.org/SETTINGS/1.1.0">
<activeProfile>ejavaPC</activeProfile>
<activeProfile>jboss6</activeProfile>
<activeProfile>hsql</activeProfile>
<activeProfile>webdev-repositories</activeProfile>
</activeProfiles>
<pluginGroups xmlns="http://maven.apache.org/SETTINGS/1.1.0">
<pluginGroup>org.apache.maven.plugins</pluginGroup>
<pluginGroup>org.codehaus.mojo</pluginGroup>
</pluginGroups>
</settings>
...> mvn help:describe -Dplugin=surefire -Dfull=true ... Mojos: =============================================== Goal: 'test' =============================================== Description: Run tests using Surefire. Implementation: org.apache.maven.plugin.surefire.SurefirePlugin Language: java Bound to Phase: test Parameters: ----------------------------------------------- [0] Name: argLine Type: java.lang.String Required: false Directly editable: true Description: Arbitrary options to set on the command line. ...
During this exercise, you were able to establish a project which was understood by Maven. Once Maven-compliant, each plugin can be added to perform different tasks for development. By the time we start adding databases, building EARs, and deploying to application servers, we can use all the plugin help we can get.