Magazine
 
Maven2
 

The maven repository folder has subfolders for each library.
For instance, there is a sub folder for commons-logging. Beneath the commons-logging folder there is another Subfolder called jars. This jars folder has the commons logging jar files suffixed by version number.

The role of the repository is immediately obvious. Instead of each project having its own copies of third party libraries, the repository helps developers across projects to share the libraries. Each project can also in turn generate its artifacts and publish it into the remote repository. The process of publishing a jar into the repository is called “install” in Maven lingo. This install process helps organizations to share internal artifacts across projects in a standard manner. This also holds the basis for continuous integration among interdependent projects.

Figure shows the pom.xml, repository and plugins. The grey colored rectangles are provided by you. The blue colored rectangles are provided by Maven. The orange colored rectangle shaded is the output - the real deployment artifact obtained for your project. Custom plug-ins are optional. The rest of the inputs are mandatory.

Installing and Getting Hands on Maven

Now that we have sufficient understanding of the pom.xml file let us get on try something out.

Download Maven from maven.apache.org, unzip the archive
into your local directory.

Set the JAVA_HOME variable to point to the JDK installation andMAVEN_HOME to point to the Maven directory and add the MAVEN_HOME/bin to the PATH environment variable.

1. To test whether the path has been set properly. Type
mvn -version on the command prompt.

C:\>mvn -versionMaven version: 2.0.7Java version:
1.5.0OS name: “windows 2000” version: “5.0” arch:“x86”

2. Note create a working directory

C:\>md maventest
C:\>cd maventest

3. Create your first project. In order to create the sim
plest of Maven projects, execute the following from the
command line:

C:\maventest>mvn archetype:create -
DarchetypeGroupId=org.apache.maven.archetypes -
DgroupId=net.roseindia.maven.quickstart -
DartifactId=HelloMaven

Once you have executed this command, you will
notice a few things have happened.

 

First, you will notice that a directory named HelloMaven has
been created for the new project,and this directory contains a file named pom.xml that should look like this.

pom.xml

<project xmlns=”http://maven.apache.org/POM/4.0.0"
xmlns:xsi=”http://www.w3.org/2001/XMLSchemainstance”
xsi:schemaLocation=”http://maven.apache.org/POM/
4.0.0 http://maven.apache.org/maven-v4_0_0.xsd”>
<modelVersion>4.0.0</modelVersion>
<groupId>net.roseindia.maven.quickstart</groupId>
<artifactId>HelloMaven</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>HelloMaven</name>
<url>http://maven.apache.org</url>bn
<dependencies><dependency><groupId>junit</groupId>
<artifactId>junit</artifactId><version>3.8.1</version>
<scope>test</scope></dependency></dependencies>
</project>

After the archetype generation of your first project you can see, the project created from the archetype has a POM, a target directory, a source tree for your application’s sources and a source tree for your test sources. This is the standard layout for Maven projects.

The application sources reside in ${basedir}/src/main/java and test sources reside in ${basedir}/src/test/java, where {basedir} represents the directory containing pom.xml.

you will notice that the following directory structure has been
created:

HelloMaven
|--pom.xml
|--target
|--src
   |--main
      |-- java
        |-- net
            |-- roseindia
               |-- maven
                 |-- quickstart
                  |-- Calculator.java
  |--test
     |-- java
         |-- net
            |-- roseindia
               |-- maven
                  |-- quickstart
                     |-- TestCalculator.java

4. Now to compile the application sources. Change to the
directory where pom.xml is created and execute the “mvn
compile” command to compile your application sources:

C:\maventest>cd HelloMaven
C:\maventest\HelloMaven>mvn compile

August 2007 | Java Jazz Up | 20
 
previous
index
next
 
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 38, 39, 40           Download PDF