1. Target
1) Get familiar with baisc maven config.
2) Integrate maven into eclipse.
2. Basic maven config
1) Download maven from http://maven.apache.org/download.cgi and choose Maven 3.0.5 (Binary zip)
2) Unzip maven.
3) Set environment variables in windows
1) add MAVEN_HOME with value D:\Program Files\apache-maven-3.0.5
2) add PATH with value %MAVEN_HOME%\bin
4) Type mvn -version in CMD to test whether the variables have been set correctly.
3. A glimpse of maven dirs
1) In conf/settings.xml, we can config proxies and repository for maven. This config file is global scope config.
2) The default location for maven respository is C:/Users/Administrator/.m2/repository.
2) C:/Users/Administrator/.m2/settings.xml is user scope config. <We need to copy golbal setting.xml to this folder as this file doesn't exists at start up>
4. A simple example using maven without IDE
1) First we create a folder: D:/workspace/maven as the root folder for our project.
2) In the folder maven, we create a simple pom.xml
<?xml version="1.0" encoding="UTF-8"?> <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>edu.xmu.maven</groupId> <artifactId>MavenExample-ModuleOn</artifactId> <packaging>jar</packaging> <version>0.0.1-SNAPSHOT</version> </project>
1) groupId---> Means the project name.
2) artifactId ---> Means a single module inside the project.
3) packaging ---> jar/war
4) modelVersion ---> Must be set as 4.0.0
5) version ---> SNAPSHOT means not RELEASE version. May be changed quite often.
3) In the folder D:/workspace/maven/src/main/java, we manually create a dir edu/xmu/maven
4) In the path D:\workspace\maven\src\main\java\edu\xmu\maven we create a Test.java file
package edu.xmu.maven; public class Test { public void sayHello(String name) { System.out.println("Hello, " + name); } }
5) In CMD, type command as below
1) We have to make sure the proxy is configured correctly in settings.xml ----> Use ping repo1.maven.org to validate if we can connect to main respository.
2) We have to make sure the JAVA_HOME is configured as jdk main folder and not as jre main folder ---> Or else, build failure occurs.
6) Inspect the compile output folder: D:\workspace\maven\target\classes
7) The destination .class file is generated as D:\workspace\maven\target\classes\edu\xmu\maven\Test.class
5. A glimpse of installed directory hierarchy after we type mvn install in CMD
1) The .jar is released as C:\Users\Administrator\.m2\repository\edu\xmu\maven\MavenExample-ModuleOne\0.0.1-SNAPSHOT\MavenExample-ModuleOne-0.0.1-SNAPSHOT.jar
2) The C:\Users\Administrator\.m2\repository is the default position we publish/install our project.
3) The \edu\xmu\maven\MavenExample-ModuleOne\0.0.1-SNAPSHOT means groupId + artifactId + version <different groupId means different project, diffetent artifactId means different module in one project>
4) The MavenExample-ModuleOne-0.0.1-SNAPSHOT.jar means artifactId + version.
6. A simple introduction of maven dir
7. A simple introducition of maven command
mvn archetype:create :Create Maven project
mvn compile :Compile source code
mvn test-compile :Compile test source code
mvn test : Run unit test
mvn site : Generate related sites
mvn clean :Clean generated target folder
mvn package : Generate .jar file
mvn install :Install .jar/.war into local maven Repository
mvn deploy:Deploy .jar/.war into remote repository
mvn eclipse:eclipse :Generate eclipse project file