Let's get started. This will chronical my way through the Apache Maven Project
mini guide and some Sonatype video tutorials. It's chaotic, but I may someday
be able to make something of this.
- I downloaded and extracted Maven from the left-hand navigation thumb at
the mini guide page.
gunzip -d apache-maven-3.0.2-bin.tar.gz
tar -xf apache-maven-3.0.2-bin.tar
-
- I invoke Maven experimentally
russ@russ-elite-book:~/dev/downloads/apache-maven-3.0.2> ./bin/mvn
Warning: JAVA_HOME environment variable is not set.
(lot's more crap here...)
-
- In consequence, I go set and export JAVA_HOME and M2_HOME
for my shell. This is important since I know that a lot of the time, I
may use Maven from outside Eclipse (on the command line). I add this to
the bottom of .profile:
export JAVA_HOME=/home/russ/dev/jdk1.6.0_21
export M2_HOME=/home/russ/dev/downloads/apache-maven-3.0.2
# Add Maven and Java to my path...
PATH="$PATH:${JAVA_HOME}/bin:${M2_HOME}/bin"
-
- Lifes good (there's no POM here and nothing to build, but Maven knows
where to find Java):
russ@russ-elite-book:~/dev/downloads/apache-maven-3.0.2> ./bin/mvn --version
Apache Maven 3.0.2 (r1056850; 2011-01-08 17:58:10-0700)
Java version: 1.6.0_21, vendor: Sun Microsystems Inc.
Java home: /home/russ/dev/jdk1.6.0_21/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "2.6.35-25-generic", arch: "amd64", family: "unix"
-
- It says to set up the classpath variable (in Eclipse) thus, presumably for
each workspace in which I intend to use Maven:
mvn -Declipse.workspace= eclipse:add-maven-repo
I think I'll work in a new Eclipse workspace just for Maven
experimentation. I'm not running Eclipse right now. Also, I have not
installed any Maven plug-ins, so I don't really know what this is going
to do.
mvn -Declipse.workspace=/home/russ/dev/workspaces/maven-workspace eclipse:add-maven-repo
This appears to be populating /home/russ/.m2/repositor.
russ@russ-elite-book:~/.m2> tree repository/
repository/
`-- org
|-- apache
| `-- maven
| `-- plugins
| |-- maven-antrun-plugin
| | `-- 1.3
| | `-- maven-antrun-plugin-1.3.pom.lastUpdated
| |-- maven-assembly-plugin
| | `-- 2.2-beta-5
| | `-- maven-assembly-plugin-2.2-beta-5.pom.lastUpdated
| |-- maven-clean-plugin
| | `-- 2.4.1
| | `-- maven-clean-plugin-2.4.1.pom.lastUpdated
| |-- maven-dependency-plugin
| | `-- 2.1
| | `-- maven-dependency-plugin-2.1.pom.lastUpdated
| |-- maven-deploy-plugin
| | `-- 2.5
| | `-- maven-deploy-plugin-2.5.pom.lastUpdated
| |-- maven-install-plugin
| | `-- 2.3.1
| | `-- maven-install-plugin-2.3.1.pom.lastUpdated
| |-- maven-release-plugin
| | `-- 2.0
| | `-- maven-release-plugin-2.0.pom.lastUpdated
| |-- maven-site-plugin
| | `-- 2.0.1
| | `-- maven-site-plugin-2.0.1.pom.lastUpdated
| `-- resolver-status.properties
`-- codehaus
`-- mojo
`-- resolver-status.properties
22 directories, 10 files
-
- Tailoring the conf/settings.xml file:
<localRepository>/home/russ/.m2/repository</localRepository>
.
.
.
<proxies>
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<host>web-proxy.austin.hp.com</host>
<port>8080</port>
</proxy>
</proxies>
-
- Planning on doing a
tutorial, I created /home/russ/dev/maven-tutorial, went there, and
created the project thus:
russ@russ-elite-book:~/dev/maven-tutorial> mvn archetype:create -DgroupId=com.mytutorial \
-DartifactId=simple
[INFO] Scanning for projects...
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-clean-\
plugin/2.4.1/maven-clean-plugin-2.4.1.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-clean-\
plugin/2.4.1/maven-clean-plugin-2.4.1.pom (5 KB at 3.9 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-\
plugins/18/maven-plugins-18.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-\
plugins/18/maven-plugins-18.pom (13 KB at 18.4 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/maven/maven-parent/16/\
maven-parent-16.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/maven-parent/16/\
maven-parent-16.pom (23 KB at 34.1 KB/sec)
.
.
.
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/doxia/doxia-sink-\
api/1.0-alpha-9/doxia-sink-api-1.0-alpha-9.jar (10 KB at 2.5 KB/sec)
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/shared/maven-invoker\
/2.0.10/maven-invoker-2.0.10.jar (28 KB at 7.7 KB/sec)
Downloaded: http://repo1.maven.org/maven2/commons-collections/commons-collections\
/3.2.1/commons-collections-3.2.1.jar (562 KB at 114.1 KB/sec)
[WARNING] This goal is deprecated. Please use mvn archetype:generate instead
[INFO] Defaulting package to group ID: com.mytutorial
Downloading: http://repo1.maven.org/maven2/org/apache/maven/archetypes/maven-\
archetype-quickstart/maven-metadata.xml
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/archetypes/maven-\
archetype-quickstart/maven-metadata.xml (531 B at 0.6 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/maven/archetypes/maven-\
archetype-quickstart/1.1/maven-archetype-quickstart-1.1.jar
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/archetypes/maven-\
archetype-quickstart/1.1/maven-archetype-quickstart-1.1.jar (7 KB at 10.8 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/maven/archetypes/maven-\
archetype-quickstart/1.1/maven-archetype-quickstart-1.1.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/archetypes/maven-\
archetype-quickstart/1.1/maven-archetype-quickstart-1.1.pom (2 KB at 2.3 KB/sec)
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: \
maven-archetype-quickstart:RELEASE
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: com.mytutorial
[INFO] Parameter: packageName, Value: com.mytutorial
[INFO] Parameter: package, Value: com.mytutorial
[INFO] Parameter: artifactId, Value: simple
[INFO] Parameter: basedir, Value: /home/russ/dev/maven-tutorial
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] ********************* End of debug info from resources from generated POM
[INFO] project created from Old (1.x) Archetype in dir: /home/russ/dev/maven-\
tutorial/simple
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:31.955s
[INFO] Finished at: Mon Jan 31 11:42:52 MST 2011
[INFO] Final Memory: 9M/118M
[INFO] ------------------------------------------------------------------------
russ@russ-elite-book:~/dev/maven-tutorial> tree simple
simple
|-- pom.xml
`-- src
|-- main
| `-- java
| `-- com
| `-- mytutorial
| `-- App.java
`-- test
`-- java
`-- com
`-- mytutorial
`-- AppTest.java
9 directories, 3 files
russ@russ-elite-book:~/dev/maven-tutorial> cd simple
russ@russ-elite-book:~/dev/maven-tutorial/simple> cat 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mytutorial</groupId>
<artifactId>simple</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>simple</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
-
- Installed m2eclipse following the first two videos. Couldn't get
right-click Run As -> Maven install to work. Network appeared very
slow and ultimately failed. Bailed to command line where, in
~/, I ran
russ@russ-elite-book:~/dev/workspaces/maven-workspace/example-project> cat pom.xml
which worked fairly quickly and succeeded.