You are on page 1of 119

Apache Maven POM

Maven
Java Maven

Maven Apache Maven

Maven Java Java SEJava EE

2015-05-17

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1

Maven - . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

Maven - . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

Maven - POM
POM.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

Maven -
.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

Maven -
.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

Maven - . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

Maven - . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

Maven - . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

Maven - & . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

10

Maven - . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

11

Maven - . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

12

Maven - . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

13

Maven - . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68

14

Maven - . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

15

Maven - . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

16

Maven - . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85

17

Maven - Web . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89

18

Maven - Elipse IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94

19

Maven - NetBeans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102

20

Maven - IntelliJ IDEA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109

1
Maven -

1 Maven - | 4

Maven

Maven Maven
Maven

Maven
Maven

Maven




SCMs



Maven
Maven

Maven

Maven Jakarta Turbine


ANT JAR CVS
Apache Maven JAR

1 Maven - | 5

Maven

Maven


Maven xml pom.xml Project Object Model (POM)
Maven Maven POM ()

Maven
Maven Maven Maven
pom.xml
${basedir}

source code

${basedir}/src/main/java

resources

${basedir}/src/main/resources

Tests

${basedir}/src/test

Complied byte code

${basedir}/target

distributable JAR

${basedir}/target/classes

Maven Maven
Maven
Maven Maven

2
Maven -

2 Maven - | 7

Maven Java JDK


JDK

Maven 3.3 JDK 1.7


Maven 3.2 JDK 1.6
Maven 3.0/3.1 JDK 1.5

Maven 10 MB Maven
500 MB

1 Java

java

Windows

c:\> java -version

Linux

$ java -version

Mac

machine:~ joseph$ java -version

Windows

java version "1.6.0_21"


Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
Java HotSpot(TM) Client VM (build 17.0-b17, mixed mode, sharing)

Linux

java version "1.6.0_21"


Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
Java HotSpot(TM) Client VM (build 17.0-b17, mixed mode, sharing)

Mac

java version "1.6.0_21"


Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
Java HotSpot(TM)64-Bit Server VM (build 17.0-b17, mixed mode, sharing)

Java Java SDKhttp://www.oracle.com/technetwork/


http://www.oracle.com/technetwork/
java/javase/downloads/index.html
java/javase/downloads/index.html Java 1.6.0_21

2 Maven - | 8

2 Java

JAVA_HOME Java

Windows

Set the environment variable JAVA_HOME to


C:\Program Files\Java\jdk1.6.0_21

Linux

export JAVA_HOME=/usr/local/java-current

Mac

export JAVA_HOME=/Library/Java/Home

Java

Windows

;C:\Program Files\Java\jdk1.6.0_21\binPath

Linux

export PATH=$PATH:$JAVA_HOME/bin/

Mac

not required

java -version Java

3 Maven

Maven 3.2.5http://maven.apache.org/download.html
http://maven.apache.org/download.html

4 Maven

Maven 3.2.5 apache-maven-3.2.5

()

Windows

C:\Program Files\Apache Software Foundation\apache-maven-3.2.5

Linux

/usr/local/apache-maven

Mac

/usr/local/apache-maven

5 Maven

M2_HOMEM2MAVEN_OPTS

2 Maven - | 9

Windows

M2_HOME=C:\Program Files\Apache Software Foundation\apache-maven-3.2.5


M2=%M2_HOME%\bin
MAVEN_OPTS=-Xms256m -Xmx512m

Linux

export M2_HOME=/usr/local/apache-maven/apache-maven-3.2.5
export M2=$M2_HOME/bin
export MAVEN_OPTS=-Xms256m -Xmx512m

Mac

export M2_HOME=/usr/local/apache-maven/apache-maven-3.2.5
export M2=$M2_HOME/bin
export MAVEN_OPTS=-Xms256m -Xmx512m

6 Maven bin

M2 Path

Windows

;%M2% Path

Linux

export PATH=$M2:$PATH

Mac

export PATH=$M2:$PATH

7 Maven

mvn

Windows

c:\> mvn --version

Linux

$ mvn --version

Mac

machine:~ joseph$ mvn --version

Windows

Apache Maven 3.2.5 (r801777; 2009-08-07 00:46:01+0530)


Java version: 1.6.0_21
Java home: C:\Program Files\Java\jdk1.6.0_21\jre

Linux

Apache Maven 3.2.5 (r801777; 2009-08-07 00:46:01+0530)


Java version: 1.6.0_21
Java home: C:\Program Files\Java\jdk1.6.0_21\jre

2 Maven - | 10

Mac

Apache Maven 3.2.5 (r801777; 2009-08-07 00:46:01+0530)


Java version: 1.6.0_21
Java home: C:\Program Files\Java\jdk1.6.0_21\jre

Apache Maven

3
Maven - POM

3 Maven - POM | 12

POM Maven xml


pom.xml
POM Maven
POM Maven POM
POM
project dependencies
plugins
goals
build profiles
project version
developers
mailing list
POM groupIdartifactId

POM

<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.companyname.project-group</groupId>
<artifactId>project</artifactId>
<version>1.0</version>
</project>

POM
POM project groupId,
groupId, artifactId,version
artifactId,version
groupId:artifactId:version
POM.xml project
project

3 Maven - POM | 13

group com.company.ban
Id
k
artifac groupId artifactId artifac
tId
t
versio artifact
n
com.company.bank:consumer-banking:1.0
com.company.bank:consumer-banking:1.1.

Super POM

POM POM POM POM ** Super PO


M**
Maven effective pomSuper pom pom.xml

Super POM mvn


mvn help:effective-pom
pom.xml pom
C:\MVN\project pom.xml
pom.xml mvn
C:\MVN\project>mvn help:effective-pom

Maven effective-pom
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'help'.
[INFO] -----------------------------------------------------------------------[INFO] Building Unnamed - com.companyname.project-group:project-name:jar:1.0
[INFO]

task-segment: [help:effective-pom] (aggregator-style)

[INFO] -----------------------------------------------------------------------[INFO] [help:effective-pom {execution: default-cli}]


[INFO]
.....
[INFO] -----------------------------------------------------------------------[INFO] BUILD SUCCESSFUL
[INFO] -----------------------------------------------------------------------[INFO] Total time: < 1 second

3 Maven - POM | 14

[INFO] Finished at: Thu Jul 05 11:41:51 IST 2012


[INFO] Final Memory: 6M/15M
[INFO] ------------------------------------------------------------------------

Effective POM
<?xml version="1.0" encoding="UTF-8"?>
<!-- ================================================================= -->
<!--

-->

<!-- Generated by Maven Help Plugin on 2012-07-05T11:41:51

-->

<!-- See: http://maven.apache.org/plugins/maven-help-plugin/


<!--

-->

-->

<!-- ================================================================= -->


<!-- ================================================================= -->
<!--

-->

<!-- Effective POM for project

-->

<!-- 'com.companyname.project-group:project-name:jar:1.0'
<!--

-->

-->

<!-- ================================================================= -->


<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 h
ttp://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.companyname.project-group</groupId>
<artifactId>project</artifactId>
<version>1.0</version>
<build>
<sourceDirectory>C:\MVN\project\src\main\java</sourceDirectory>
<scriptSourceDirectory>src/main/scripts</scriptSourceDirectory>
<testSourceDirectory>C:\MVN\project\src\test\java</testSourceDirectory>
<outputDirectory>C:\MVN\project\target\classes</outputDirectory>
<testOutputDirectory>C:\MVN\project\target\test-classes</testOutputDirectory>
<resources>
<resource>
<mergeId>resource-0</mergeId>
<directory>C:\MVN\project\src\main\resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<mergeId>resource-1</mergeId>
<directory>C:\MVN\project\src\test\resources</directory>
</testResource>
</testResources>

3 Maven - POM | 15

<directory>C:\MVN\project\target</directory>
<finalName>project-1.0</finalName>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-2</version>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.0</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.3.1</version>
</plugin>
<plugin>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.1</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>

3 Maven - POM | 16

<artifactId>maven-javadoc-plugin</artifactId>
<version>2.5</version>
</plugin>
<plugin>
<artifactId>maven-plugin-plugin</artifactId>
<version>2.4.3</version>
</plugin>
<plugin>
<artifactId>maven-rar-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.0-beta-8</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.3</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>2.0-beta-7</version>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.0.4</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.3</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1-alpha-2</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-help-plugin</artifactId>
<version>2.1.1</version>
</plugin>
</plugins>
</build>
<repositories>

3 Maven - POM | 17

<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Maven Repository Switchboard</name>
<url>http://repo1.maven.org/maven2</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Maven Plugin Repository</name>
<url>http://repo1.maven.org/maven2</url>
</pluginRepository>
</pluginRepositories>
<reporting>
<outputDirectory>C:\MVN\project\target/site</outputDirectory>
</reporting>
</project>

pom.xml Maven

Maven pom.xml
Maven pom.xml
Maven - () Maven - ()

4
Maven -

4 Maven - | 19

sequence of phases

Maven

prepare-resources

compile

package

pom.xml JAR / WAR

install

pre post

Maven Maven

clean
default(or build)
site

clean package
dependency:copy-dependencies
mvn clean dependency:copy-dependencies package

clean dependency:copy-dependencies package

Clean

mvn post-clean Maven clean


pre-clean
clean

4 Maven - | 20

post-clean
Maven clean clean:clean clean clean clean:clean
mvn clean Maven
clean
maven-antrun-plugin:run pre-cleanclean post-clean
clean
C:\MVN\project 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.companyname.projectgroup</groupId>
<artifactId>project</artifactId>
<version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>id.pre-clean</id>
<phase>pre-clean</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>pre-clean phase</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>id.clean</id>
<phase>clean</phase>
<goals>
<goal>run</goal>
</goals>

4 Maven - | 21

<configuration>
<tasks>
<echo>clean phase</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>id.post-clean</id>
<phase>post-clean</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>post-clean phase</echo>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

pom.xml mvn
C:\MVN\project>mvn post-clean

Maven clean
[INFO] Scanning for projects...
[INFO] -----------------------------------------------------------------[INFO] Building Unnamed - com.companyname.projectgroup:project:jar:1.0
[INFO]

task-segment: [post-clean]

[INFO] -----------------------------------------------------------------[INFO] [antrun:run {execution: id.pre-clean}]


[INFO] Executing tasks
[echo] pre-clean phase
[INFO] Executed tasks
[INFO] [clean:clean {execution: default-clean}]
[INFO] [antrun:run {execution: id.clean}]
[INFO] Executing tasks
[echo] clean phase
[INFO] Executed tasks
[INFO] [antrun:run {execution: id.post-clean}]
[INFO] Executing tasks

4 Maven - | 22

[echo] post-clean phase


[INFO] Executed tasks
[INFO] -----------------------------------------------------------------[INFO] BUILD SUCCESSFUL
[INFO] -----------------------------------------------------------------[INFO] Total time: < 1 second
[INFO] Finished at: Sat Jul 07 13:38:59 IST 2012
[INFO] Final Memory: 4M/44M
[INFO] ------------------------------------------------------------------

mvn clean pre-clean clean post-clean

Default (or Build)

Maven 23

validate

initialize

generate-sources

process-sources

filter any value

generate-resources

process-resources

compile

process-classes

Java Class

generate-test-source
s
process-test-source
s

filter any values)

test-compile

process-test-classes
test

JUnit

prepare-package

package

JARWAR EAR

pre-integration-test

integration-test

post-integration-test

verify

install

4 Maven - | 23

deploy

Maven
Maven mvn compile

maven JAR / WAR / EAR Maven


maven-antrun-plugin:run Build

C:\MVN\project 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.companyname.projectgroup</groupId>
<artifactId>project</artifactId>
<version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>id.validate</id>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>validate phase</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>id.compile</id>
<phase>compile</phase>

4 Maven - | 24

<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>compile phase</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>id.test</id>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>test phase</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>id.package</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>package phase</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>id.deploy</id>
<phase>deploy</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>deploy phase</echo>
</tasks>
</configuration>
</execution>

4 Maven - | 25

</executions>
</plugin>
</plugins>
</build>
</project>

pom.xml mvn
C:\MVN\project>mvn compile

Maven
[INFO] Scanning for projects...
[INFO] -----------------------------------------------------------------[INFO] Building Unnamed - com.companyname.projectgroup:project:jar:1.0
[INFO]

task-segment: [compile]

[INFO] -----------------------------------------------------------------[INFO] [antrun:run {execution: id.validate}]


[INFO] Executing tasks
[echo] validate phase
[INFO] Executed tasks
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\MVN\project\src\main\resources
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [antrun:run {execution: id.compile}]
[INFO] Executing tasks
[echo] compile phase
[INFO] Executed tasks
[INFO] -----------------------------------------------------------------[INFO] BUILD SUCCESSFUL
[INFO] -----------------------------------------------------------------[INFO] Total time: 2 seconds
[INFO] Finished at: Sat Jul 07 20:18:25 IST 2012
[INFO] Final Memory: 7M/64M
[INFO] ------------------------------------------------------------------

Site

Maven Site

4 Maven - | 26

pre-site
site
post-site
site-deploy
maven-antrun-plugin:run Site

C:\MVN\project 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.companyname.projectgroup</groupId>
<artifactId>project</artifactId>
<version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>id.pre-site</id>
<phase>pre-site</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>pre-site phase</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>id.site</id>
<phase>site</phase>
<goals>
<goal>run</goal>
</goals>

4 Maven - | 27

<configuration>
<tasks>
<echo>site phase</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>id.post-site</id>
<phase>post-site</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>post-site phase</echo>
</tasks>
</configuration>
</execution>
<execution>
<id>id.site-deploy</id>
<phase>site-deploy</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>site-deploy phase</echo>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

pom.xml mvn
C:\MVN\project>mvn site

Maven site site


[INFO] Scanning for projects... [INFO] ----------------------------------------------------------------- [INFO] Building Unnamed - com.companyname.projectgroup:project:jar:1.0 [INFO] tas
k-segment: [site] [INFO] -------------------------------------------------------------

4 Maven - | 28

----- [INFO] [antrun:run {execution: id.pre-site}] [INFO] Executing tasks [echo] pre-site phase [INFO] Exe
cuted tasks [INFO] [site:site {execution: default-site}] [INFO] Generating "About" report. [INFO] Generating "I
ssue Tracking" report. [INFO] Generating "Project Team" report. [INFO] Generating "Dependencies" report.
[INFO] Generating "Project Plugins" report. [INFO] Generating "Continuous Integration" report. [INFO] Gener
ating "Source Repository" report. [INFO] Generating "Project License" report. [INFO] Generating "Mailing List
s" report. [INFO] Generating "Plugin Management" report. [INFO] Generating "Project Summary" report. [INF
O] [antrun:run {execution: id.site}] [INFO] Executing tasks [echo] site phase [INFO] Executed tasks [INFO] ----------------------------------------------------------------- [INFO] BUILD SUC
CESSFUL [INFO] -----------------------------------------------------------------[INFO] Total time: 3 seconds [INFO] Finished at: Sat Jul 07 15:25:10 IST 2012 [INFO] Final Memory: 24M/149
M [INFO] ------------------------------------------------------------------

5
Maven -

5 Maven - | 30

Maven
Producation Development
Profile pom.xml activeProfiles / profiles Profile
POM

Profile

Profile

Per Project

POM pom.xml

Per User

Maven xml %USER_HOME%/.m2/settings.xml

Global

Maven xml %M2_HOME%/conf/settings.xml

Profile

Maven Profile

maven
/
Windows family
/

Profile

5 Maven - | 31

5.1 Maven Build Profile


src/main/resources

env.properties

env.test.properties

env.prod.properties

Profile

attach maven-antrun-plugin:run
Profile pom.xml Profile maven
Profile
C:\MVN\project 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.companyname.projectgroup</groupId>
<artifactId>project</artifactId>
<version>1.0</version>

5 Maven - | 32

<profiles>
<profile>
<id>test</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>Using env.test.properties</echo>
<copy file="src/main/resources/env.test.propertiestofile
="${project.build.outputDirectory}/env.properties"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

pom.xml mvn -P Profile


C:\MVN\project>mvn test -Ptest

Maven test Profile


[INFO] Scanning for projects...
[INFO] -----------------------------------------------------------------[INFO] Building Unnamed - com.companyname.projectgroup:project:jar:1.0
[INFO]

task-segment: [test]

[INFO] -----------------------------------------------------------------[INFO] [resources:resources {execution: default-resources}]


[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] Copying 3 resources

5 Maven - | 33

[INFO] [compiler:compile {execution: default-compile}]


[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources {execution: default-testResources}]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\MVN\project\src\test\resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [surefire:test {execution: default-test}]
[INFO] Surefire report directory: C:\MVN\project\target\surefire-reports
## ## T E S T SThere are no tests to run.
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] [antrun:run {execution: default}]
[INFO] Executing tasks
[echo] Using env.test.properties
[INFO] Executed tasks
[INFO] -----------------------------------------------------------------[INFO] BUILD SUCCESSFUL
[INFO] -----------------------------------------------------------------[INFO] Total time: 1 second
[INFO] Finished at: Sun Jul 08 14:55:41 IST 2012
[INFO] Final Memory: 8M/64M
[INFO] ------------------------------------------------------------------

pom.xml profiles profile profile profiles

profile id test normal


echo env.properties copy env.properties
id prod task env.prod.properties
normal / test / prod
pom.xml mvn -P Profile

C:\MVN\project>mvn test -Pnormal


C:\MVN\project>mvn test -Pprod

5 Maven - | 34

Maven Profile

Maven settings.xml %USER_HOME%/.m2 %USER_HOME%


%USER_HOME%
settings.xml
activeProfiles test Profile
<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">
<mirrors>
<mirror>
<id>maven.dev.snaponglobal.com</id>
<name>Internal Artifactory Maven repository</name>
<url>http://repo1.maven.org/maven2/</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
<activeProfiles>
<activeProfile>test</activeProfile>
</activeProfiles>
</settings>

pom.xml mvn -P Profile


Maven test Profile
C:\MVN\project>mvn test

Profile

maven settings.xml Profile pom.xml test Profile


profile activation
env test test env
test
<profile>
<id>test</id>

5 Maven - | 35

<activation>
<property>
<name>env</name>
<value>test</value>
</property>
</activation>
</profile>

pom.xml mvn
C:\MVN\project>mvn test

Profile

activation windows XP test Profile


<profile>
<id>test</id>
<activation>
<os>
<name>Windows XP</name>
<family>Windows</family>
<arch>x86</arch>
<version>5.1.2600</version>
</os>
</activation>
</profile>

pom.xml mvn -P Profile


Maven test Profile
C:\MVN\project>mvn test

/ Profile

activation target/generated-sources/axistools/wsdl2java/co

m/companyname/group test Profile


<profile>
<id>test</id>
<activation>
<file>
<missing>target/generated-sources/axistools/wsdl2java/

5 Maven - | 36

com/companyname/group</missing>
</file>
</activation>
</profile>

pom.xml mvn -P Profile


Maven test Profile
C:\MVN\project>mvn test

6
Maven -

6 Maven - | 38

Maven

Maven place jar library jar

Maven
local
central
remote

Maven maven
Maven library jarplugin jar Maven Maven
jar
Maven %USER_HOME% %M2_HOME%\conf
Maven settings.xml
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>C:/MyLocalRepository</localRepository>
</settings>

Maven Maven

Maven Maven

Maven

6 Maven - | 39


maven URLhttp://search.maven.org/#browse
http://search.maven.org/#browse

Maven
Maven
jar
POM.xmlMaven 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.companyname.projectgroup</groupId>
<artifactId>project</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>com.companyname.common-lib</groupId>
<artifactId>common-lib</artifactId>
<version>1.0.0</version>
</dependency>
<dependencies>
<repositories>
<repository>
<id>companyname.lib1</id>
<url>http://download.companyname.org/maven2/lib1</url>
</repository>
<repository>
<id>companyname.lib2</id>
<url>http://download.companyname.org/maven2/lib2</url>
</repository>
</repositories>
</project>

6 Maven - | 40

Maven

Maven Maven
1 2
2 4

3 Maven
4 Mave
n

7
Maven -

7 Maven - | 42

Maven

Maven Maven
jar
war



mvn [plugin-name]:[goal-name]

Java maven-compiler-plugin compile-goal


mvn compiler:compile

Maven

Build plugins

pom.xml

Reporting plugins

pom.xml

clean

compiler

Java

surefile

JUnit

jar

JAR

war

WAR

javadoc

Javadoc

antrun

ant

7 Maven - | 43

maven-antrun-plugin Maven -
() C:\MVN\project 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.companyname.projectgroup</groupId>
<artifactId>project</artifactId>
<version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>id.clean</id>
<phase>clean</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>clean phase</echo>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

pom.xml mvn
C:\MVN\project>mvn clean

7 Maven - | 44

Maven clean clean


[INFO] Scanning for projects...
[INFO] -----------------------------------------------------------------[INFO] Building Unnamed - com.companyname.projectgroup:project:jar:1.0
[INFO]

task-segment: [post-clean]

[INFO] -----------------------------------------------------------------[INFO] [clean:clean {execution: default-clean}]


[INFO] [antrun:run {execution: id.clean}]
[INFO] Executing tasks
[echo] clean phase
[INFO] Executed tasks
[INFO] -----------------------------------------------------------------[INFO] BUILD SUCCESSFUL
[INFO] -----------------------------------------------------------------[INFO] Total time: < 1 second
[INFO] Finished at: Sat Jul 07 13:38:59 IST 2012
[INFO] Final Memory: 4M/44M
[INFO] ------------------------------------------------------------------

pom.xml plugins

phase clean
echo maven-antrunplugin run
Maven

8
Maven -

8 Maven - | 46

Maven archetype
archetype Java maven-archetyp
e-quickstart C:\MVN maven java
C:\MVN mvn
C:\MVN>mvn archetype:generate
-DgroupId=com.companyname.bank
-DartifactId=consumerBanking
-DarchetypeArtifactId=maven-archetype-quickstart
-DinteractiveMode=false

Maven java
INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] ------------------------------------------------------------------[INFO] Building Maven Default Project
[INFO]

task-segment: [archetype:generate] (aggregator-style)

[INFO] ------------------------------------------------------------------[INFO] Preparing archetype:generate


[INFO] No goals needed for project - skipping
[INFO] [archetype:generate {execution: default-cli}]
[INFO] Generating project in Batch mode
[INFO] ------------------------------------------------------------------[INFO] Using following parameters for creating project
from Old (1.x) Archetype: maven-archetype-quickstart:1.0
[INFO] ------------------------------------------------------------------[INFO] Parameter: groupId, Value: com.companyname.bank
[INFO] Parameter: packageName, Value: com.companyname.bank
[INFO] Parameter: package, Value: com.companyname.bank
[INFO] Parameter: artifactId, Value: consumerBanking
[INFO] Parameter: basedir, Value: C:\MVN
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: C:\MVN\consumerBanking
[INFO] -----------------------------------------------------------------[INFO] BUILD SUCCESSFUL
[INFO] -----------------------------------------------------------------[INFO] Total time: 14 seconds
[INFO] Finished at: Tue Jul 10 15:38:58 IST 2012
[INFO] Final Memory: 21M/124M
[INFO] ------------------------------------------------------------------

C:/MVN consumerBanking java artifactId


Maven

8 Maven - | 47

8.1 Java application project structure

consumerBanking

src pom.xml

src/main/java contains

java com/companyName/bank

src/main/test contains

com/companyName/bank

src/main/resources

Maven Java Java C:\MVN\consumerBanking\src\main\jav


a\com\companyname\bank App.java
package com.companyname.bank;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}

8 Maven - | 48

C:\MVN\consumerBanking\src\test\java\com\companyname\bank AppTest.jav
a
package com.companyname.bank;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Unit test for simple App.
*/
public class AppTest extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
assertTrue( true );
}
}

Maven

maven Maven
Maven - & ()

9
Maven - &

9 Maven - & | 50

Maven Java
C:/MVN java consumerBanking 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.companyname.projectgroup</groupId>
<artifactId>project</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
</dependency>
</dependencies>
</project>

Maven JUnit Maven App.java


AppTest.java
C:\MVN\consumerBanking mvn
C:\MVN\consumerBanking>mvn clean package

Maven
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------[INFO] Building consumerBanking
[INFO]

task-segment: [clean, package]

[INFO] ------------------------------------------------------------------[INFO] [clean:clean {execution: default-clean}]


[INFO] Deleting directory C:\MVN\consumerBanking\target
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\MVN\consumerBanking\src\main\
resources
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Compiling 1 source file to C:\MVN\consumerBanking\target\classes

9 Maven - & | 51

[INFO] [resources:testResources {execution: default-testResources}]


[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\MVN\consumerBanking\src\test\
resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Compiling 1 source file to C:\MVN\consumerBanking\target\test-classes
[INFO] [surefire:test {execution: default-test}]
[INFO] Surefire report directory: C:\MVN\consumerBanking\target\
## surefire-reports## T E S T SRunning com.companyname.bank.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.027 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] [jar:jar {execution: default-jar}]
[INFO] Building jar: C:\MVN\consumerBanking\target\
consumerBanking-1.0-SNAPSHOT.jar
[INFO] -----------------------------------------------------------------------[INFO] BUILD SUCCESSFUL
[INFO] -----------------------------------------------------------------------[INFO] Total time: 2 seconds
[INFO] Finished at: Tue Jul 10 16:52:18 IST 2012
[INFO] Final Memory: 16M/89M
[INFO] ------------------------------------------------------------------------

jar
maven clean jarpackage

jar consumerBanking\target consumerBanking-1.0-SNAPSH


OT.jar
consumerBanking\target\surefire-reports
Maven
Maven
Maven
C:\MVN\consumerBanking\target\classes java
C:\MVN\consumerBanking\target\classes>java com.companyname.bank.App

9 Maven - & | 52

Hello World!

Java

Java C:\MVN\consumerBanking\src\main\java\com\compa
nyname\bank Util Util.java
package com.companyname.bank;
public class Util
{
public static void printMessage(String message){
System.out.println(message);
}
}

App Util
package com.companyname.bank;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
Util.printMessage("Hello World!");
}
}

C:\MVN\consumerBanking mvn
C:\MVN\consumerBanking>mvn clean compile

Maven C:\MVN\consumerBanking\target\classes java

C:\MVN\consumerBanking\target\classes>java -cp com.companyname.bank.App

9 Maven - & | 53

Hello World!

10
Maven -

10 Maven - | 55

Maven Maven - ()
? Maven
Maven - ()
src lib
jar lib ldapjdk.jar LDAP

10.1 external-project-structure
library maven j
ar Maven

maven 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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.companyname.bank</groupId>
<artifactId>consumerBanking</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>consumerBanking</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>

10 Maven - | 56

<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ldapjdk</groupId>
<artifactId>ldapjdk</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${basedir}\src\lib\ldapjdk.jar</systemPath>
</dependency>
</dependencies>
</project>

<dependencies> <dependency> ,

library jar location pom.xml


groupId library
artifactId library
scope

Maven

11
Maven -

11 Maven - | 58

C:/ MVN java consumerBa


nking consumerBanking mvn
C:\MVN>mvn site

Maven
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------[INFO] Building consumerBanking
[INFO]task-segment: [site]
[INFO] ------------------------------------------------------------------[INFO] [site:site {execution: default-site}]
[INFO] artifact org.apache.maven.skins:maven-default-skin:
checking for updates from central
[INFO] Generating "About" report.
[INFO] Generating "Issue Tracking" report.
[INFO] Generating "Project Team" report.
[INFO] Generating "Dependencies" report.
[INFO] Generating "Continuous Integration" report.
[INFO] Generating "Source Repository" report.
[INFO] Generating "Project License" report.
[INFO] Generating "Mailing Lists" report.
[INFO] Generating "Plugin Management" report.
[INFO] Generating "Project Summary" report.
[INFO] ------------------------------------------------------------------[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------[INFO] Total time: 16 seconds
[INFO] Finished at: Wed Jul 11 18:11:18 IST 2012
[INFO] Final Memory: 23M/148M
[INFO] -------------------------------------------------------------------

11 Maven - | 59

C:\MVN\consumerBanking\target\site index.html

Maven Doxia
Doxia

11 Maven - | 60

XDoc

Maven 1.x

http://jakarta.apache.org/site/jakarta-site2.html

FML

FAQ

http://maven.apache.org/doxia/references/fml-format.html

XHTML

HTML

http://en.wikipedia.org/wiki/XHTML

12
Maven -

12 Maven - | 62

Maven Archetype614 Maven


java
mvn archetype:generate

Maven quickstart
java

C:\ > MVN mvn


C:\MVN>mvn archetype:generate

Maven
INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] ------------------------------------------------------------------[INFO] Building Maven Default Project
[INFO]task-segment: [archetype:generate] (aggregator-style)
[INFO] ------------------------------------------------------------------[INFO] Preparing archetype:generate
...
600: remote -> org.trailsframework:trails-archetype (-)
601: remote -> org.trailsframework:trails-secure-archetype (-)
602: remote -> org.tynamo:tynamo-archetype (-)
603: remote -> org.wicketstuff.scala:wicket-scala-archetype (-)
604: remote -> org.wicketstuff.scala:wicketstuff-scala-archetype
Basic setup for a project that combines Scala and Wicket,
depending on the Wicket-Scala project.
Includes an example Specs test.)
605: remote -> org.wikbook:wikbook.archetype (-)
606: remote -> org.xaloon.archetype:xaloon-archetype-wicket-jpa-glassfish (-)
607: remote -> org.xaloon.archetype:xaloon-archetype-wicket-jpa-spring (-)
608: remote -> org.xwiki.commons:xwiki-commons-component-archetype
(Make it easy to create a maven project for creating XWiki Components.)
609: remote -> org.xwiki.rendering:xwiki-rendering-archetype-macro
(Make it easy to create a maven project for creating XWiki Rendering Macros.)
610: remote -> org.zkoss:zk-archetype-component (The ZK Component archetype)

12 Maven - | 63

611: remote -> org.zkoss:zk-archetype-webapp (The ZK wepapp archetype)


612: remote -> ru.circumflex:circumflex-archetype (-)
613: remote -> se.vgregion.javg.maven.archetypes:javg-minimal-archetype (-)
614: remote -> sk.seges.sesam:sesam-annotation-archetype (-)
Choose a number or apply filter
(format: [groupId:]artifactId, case sensitive contains): 203:

Enter (203:maven-archetype-quickstart)
Maven
Choose org.apache.maven.archetypes:maven-archetype-quickstart version:
1: 1.0-alpha-1
2: 1.0-alpha-2
3: 1.0-alpha-3
4: 1.0-alpha-4
5: 1.0
6: 1.1
Choose a number: 6:

Enter (6:maven-archetype-quickstart:1.1)
Maven Enter

Define value for property 'groupId': : com.companyname.insurance


Define value for property 'artifactId': : health
Define value for property 'version': 1.0-SNAPSHOT:
Define value for property 'package': com.companyname.insurance:

Maven enter Y
Confirm properties configuration:
groupId: com.companyname.insurance
artifactId: health
version: 1.0-SNAPSHOT
package: com.companyname.insurance
Y:

Maven :
[INFO] ----------------------------------------------------------------------[INFO] Using following parameters for creating project
from Old (1.x) Archetype: maven-archetype-quickstart:1.1
[INFO] ----------------------------------------------------------------------[INFO] Parameter: groupId, Value: com.companyname.insurance

12 Maven - | 64

[INFO] Parameter: packageName, Value: com.companyname.insurance


[INFO] Parameter: package, Value: com.companyname.insurance
[INFO] Parameter: artifactId, Value: health
[INFO] Parameter: basedir, Value: C:\MVN
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: C:\MVN\health
[INFO] ----------------------------------------------------------------------[INFO] BUILD SUCCESSFUL
[INFO] ----------------------------------------------------------------------[INFO] Total time: 4 minutes 12 seconds
[INFO] Finished at: Fri Jul 13 11:10:12 IST 2012
[INFO] Final Memory: 20M/90M
[INFO] -----------------------------------------------------------------------

C:\ > MVN health java arti


factId Maven :

POM.xml

Maven 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

12 Maven - | 65

http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.companyname.insurance</groupId>
<artifactId>health</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>health</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>

App.java

Maven java App.java :


C:\
C:\ > MVN > health > src > main > java > com > companyname > insurance > App.java
package com.companyname.insurance;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}

12 Maven - | 66

AppTest.java

Maven java AppTest.java


C:\ > MVN > health > src > test > java > com > companyname > insurance > AppTest.java
package com.companyname.insurance;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Unit test for simple App.
*/
public class AppTest
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
assertTrue( true );

12 Maven - | 67

}
}

Maven maven

13
Maven -

13 Maven - | 69

app-ui.jar:1.0)data-servic
e.jar:1.0
bug release


pom.xml

Maven

data-service:1.0-SNAPSHOT
jar

vs

Maven data-service:1.0
1.0 1.1
Maven data-service:1.0-SNAPS
HOT

pom.xml

1.0
<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>

13 Maven - | 70

<groupId>app-ui</groupId>
<artifactId>app-ui</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>health</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>data-service</groupId>
<artifactId>data-service</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

pom.xml

release 1.0
<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>data-service</groupId>
<artifactId>data-service</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>health</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

Maven maven -U maven

mvn clean package -U

13 Maven - | 71

C:\ > MVN > app-ui mvn


C:\MVN\app-ui>mvn clean package -U

Maven
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------[INFO] Building consumerBanking
[INFO]

task-segment: [clean, package]

[INFO] ------------------------------------------------------------------[INFO] Downloading data-service:1.0-SNAPSHOT


[INFO] 290K downloaded.
[INFO] [clean:clean {execution: default-clean}]
[INFO] Deleting directory C:\MVN\app-ui\target
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\MVN\app-ui\src\main\
resources
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Compiling 1 source file to C:\MVN\app-ui\target\classes
[INFO] [resources:testResources {execution: default-testResources}]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\MVN\app-ui\src\test\
resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Compiling 1 source file to C:\MVN\app-ui\target\test-classes
[INFO] [surefire:test {execution: default-test}]
[INFO] Surefire report directory: C:\MVN\app-ui\target\
## surefire-reports## T E S T SRunning com.companyname.bank.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.027 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] [jar:jar {execution: default-jar}]
[INFO] Building jar: C:\MVN\app-ui\target\
app-ui-1.0-SNAPSHOT.jar
[INFO] -----------------------------------------------------------------------[INFO] BUILD SUCCESSFUL
[INFO] -----------------------------------------------------------------------[INFO] Total time: 2 seconds

13 Maven - | 72

[INFO] Finished at: Tue Jul 10 16:52:18 IST 2012


[INFO] Final Memory: 16M/89M
[INFO] ------------------------------------------------------------------------

14
Maven -

14 Maven - | 74

Api bus-core-api 2
UI app-web-ui UI app-desktop-ui
app-web-ui 1.0-SNAPSHOT Api POM
<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>app-web-ui</groupId>
<artifactId>app-web-ui</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>bus-core-api</groupId>
<artifactId>bus-core-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

app-desktop-ui 1.0-SNAPSHOT Api POM


<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>app-desktop-ui</groupId>
<artifactId>app-desktop-ui</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>bus-core-api</groupId>
<artifactId>bus-core-api</artifactId>
<version>1.0-SNAPSHOT</version>

14 Maven - | 75

</dependency>
</dependencies>
</project>

bus-core-api POM
<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>bus-core-api</groupId>
<artifactId>bus-core-api</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
</project>

app-web-ui app-desktop-ui bus-core-api

bus-core-api

2
bus-core-api pom app-web-ui app-desktop-ui

CI Hudson

Maven

bus-core-api 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>bus-core-api</groupId>
<artifactId>bus-core-api</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<build>

14 Maven - | 76

<plugins>
<plugin>
<artifactId>maven-invoker-plugin</artifactId>
<version>1.6</version>
<configuration>
<debug>true</debug>
<pomIncludes>
<pomInclude>app-web-ui/pom.xml</pomInclude>
<pomInclude>app-desktop-ui/pom.xml</pomInclude>
</pomIncludes>
</configuration>
<executions>
<execution>
<id>build</id>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<build>
</project>

C:\ > MVN > bus-core-api mvn


C:\MVN\bus-core-api>mvn clean package -U

Maven bus-core-api
[INFO] Scanning for projects...
[INFO] -----------------------------------------------------------------[INFO] Building bus-core-api
[INFO]

task-segment: [clean, package]

[INFO] -----------------------------------------------------------------...
[INFO] [jar:jar {execution: default-jar}]
[INFO] Building jar: C:\MVN\bus-core-ui\target\
bus-core-ui-1.0-SNAPSHOT.jar
[INFO] -----------------------------------------------------------------[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------

bus-core-api Maven app-web-ui

14 Maven - | 77

[INFO] -----------------------------------------------------------------[INFO] Building app-web-ui


[INFO]

task-segment: [package]

[INFO] -----------------------------------------------------------------...
[INFO] [jar:jar {execution: default-jar}]
[INFO] Building jar: C:\MVN\app-web-ui\target\
app-web-ui-1.0-SNAPSHOT.jar
[INFO] -----------------------------------------------------------------[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------

app-web-ui Maven app-desktop-ui


[INFO] -----------------------------------------------------------------[INFO] Building app-desktop-ui
[INFO]

task-segment: [package]

[INFO] -----------------------------------------------------------------...
[INFO] [jar:jar {execution: default-jar}]
[INFO] Building jar: C:\MVN\app-desktop-ui\target\
app-desktop-ui-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------[INFO] BUILD SUCCESSFUL
[INFO] -------------------------------------------------------------------

CI

bus-core-api pom
app-mobile-ui bus-core-ui Hud
son Maven

14 Maven - | 78

14.1 automated build


Hunson svn Hudson
Hunson

bus-core-api SVN Hudson H


udson app-web-ui app-desktop-ui

15
Maven -

15 Maven - | 80

Maven
Maven

A B. C A,
B
Maven pom.xmlMaven

pom Maven

Maven

C B B
A A B

"exclusion" A B B C A
C

"optional" A B B C
B C A C

JDK

15 Maven - | 81

pom POM

POM

pom
pom pom pom

15.1 dependency graph

App-UI-WAR App-Core-lib App-Data-lib.


Root App-Core-lib App-Data-lib
Root Lib1,lib2, Lib3 3
App-UI-WAR POM
<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.companyname.groupname</groupId>
<artifactId>App-UI-WAR</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<dependencies>
<dependency>

15 Maven - | 82

<groupId>com.companyname.groupname</groupId>
<artifactId>App-Core-lib</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<dependencies>
<dependency>
<groupId>com.companyname.groupname</groupId>
<artifactId>App-Data-lib</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>

App-Core-lib POM
<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">
<parent>
<artifactId>Root</artifactId>
<groupId>com.companyname.groupname</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.companyname.groupname</groupId>
<artifactId>App-Core-lib</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
</project>

App-Data-lib POM
<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">
<parent>
<artifactId>Root</artifactId>
<groupId>com.companyname.groupname</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.companyname.groupname</groupId>
<artifactId>App-Data-lib</artifactId>

15 Maven - | 83

<version>1.0</version>
<packaging>jar</packaging>
</project>

Root POM
<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.companyname.groupname</groupId>
<artifactId>Root</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<dependencies>
<dependency>
<groupId>com.companyname.groupname1</groupId>
<artifactId>Lib1</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<dependencies>
<dependency>
<groupId>com.companyname.groupname2</groupId>
<artifactId>Lib2</artifactId>
<version>2.1</version>
</dependency>
</dependencies>
<dependencies>
<dependency>
<groupId>com.companyname.groupname3</groupId>
<artifactId>Lib3</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
</project>

App-UI-WAR Maven

pom App-Data-lib App-Core-lib Root


Root POM.

15 Maven - | 84

App-UI-W Lib1, lib2, Lib3 Maven

16
Maven -

16 Maven - | 86

SVN
SVN

WAR EAR

Maven
SubVersion,
(Jfrog/Nexus)

POM.xml

Maven
bus-core-api 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>bus-core-api</groupId>
<artifactId>bus-core-api</artifactId>

16 Maven - | 87

<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<scm>
<url>http://www.svn.com</url>
<connection>scm:svn:http://localhost:8080/svn/jrepo/trunk/
Framework</connection>
<developerConnection>scm:svn:${username}/${password}@localhost:8080:
common_core_api:1101:code</developerConnection>
</scm>
<distributionManagement>
<repository>
<id>Core-API-Java-Release</id>
<name>Release repository</name>
<url>http://localhost:8081/nexus/content/repositories/
Core-Api-Release</url>
</repository>
</distributionManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.0-beta-9</version>
<configuration>
<useReleaseProfile>false</useReleaseProfile>
<goals>deploy</goals>
<scmCommentPrefix>[bus-core-api-release-checkin]-<
/scmCommentPrefix>
</configuration>
</plugin>
</plugins>
</build>
</project>

pom.xml

SCM

SVN Maven

WAR/EAR/JAR

maven-release-plugin

Maven Release

Maven maven-release-plugin

16 Maven - | 88

mvn release:clean

mvn release:rollback

mvn release:prepare




POM SVN

POM
SVN

POM SVN.
mvn release:perform

Maven WAR
C:\ > MVN >bus-core-api mvn
C:\MVN\bus-core-api>mvn release:prepare

Maven mvn
C:\MVN\bus-core-api>mvn release:perform

JAR

17
Maven - Web

17 Maven - Web | 90

Maven Web //
Web

Web

Java web maven-archetype-webapp


C:\MVN mvn
C:\MVN>mvn archetype:generate
-DgroupId=com.companyname.automobile
-DartifactId=trucks
-DarchetypeArtifactId=maven-archetype-webapp
-DinteractiveMode=false

Maven Web java


[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] ------------------------------------------------------------------[INFO] Building Maven Default Project
[INFO]

task-segment: [archetype:generate] (aggregator-style)

[INFO] ------------------------------------------------------------------[INFO] Preparing archetype:generate


[INFO] No goals needed for project - skipping
[INFO] [archetype:generate {execution: default-cli}]
[INFO] Generating project in Batch mode
[INFO] -------------------------------------------------------------------[INFO] Using following parameters for creating project
from Old (1.x) Archetype: maven-archetype-webapp:1.0
[INFO] -------------------------------------------------------------------[INFO] Parameter: groupId, Value: com.companyname.automobile
[INFO] Parameter: packageName, Value: com.companyname.automobile
[INFO] Parameter: package, Value: com.companyname.automobile
[INFO] Parameter: artifactId, Value: trucks
[INFO] Parameter: basedir, Value: C:\MVN
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: C:\MVN\trucks
[INFO] ------------------------------------------------------------------[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------[INFO] Total time: 16 seconds
[INFO] Finished at: Tue Jul 17 11:00:00 IST 2012

17 Maven - Web | 91

[INFO] Final Memory: 20M/89M


[INFO] -------------------------------------------------------------------

C:/MVN trucks artifactld java

17.1 Java web application project structure


Maven

trucks

src pom.xml

src/main/webapp

index.jsp WEB-INF .

src/main/webapp/WEB-INF

web.xml

src/main/resources

images / properties

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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.companyname.automobile</groupId>
<artifactId>trucks</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>trucks Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>

17 Maven - Web | 92

<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>trucks</finalName>
</build>
</project>

Maven JSP
C:\ > MVN > trucks > src > main > webapp > , index.jsp.
<html>
<body>
<h2>Hello World!</h2>
</body>
</html>

Build Web Application

C:\MVN\trucks mvn .
C:\MVN\trucks>mvn clean package

Maven
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------[INFO] Building trucks Maven Webapp
[INFO]

task-segment: [clean, package]

[INFO] ------------------------------------------------------------------[INFO] [clean:clean {execution: default-clean}]


[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (Cp1252 actually) to
copy filtered resources,i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] [compiler:compile {execution: default-compile}]
[INFO] No sources to compile
[INFO] [resources:testResources {execution: default-testResources}]
[WARNING] Using platform encoding (Cp1252 actually) to
copy filtered resources,i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory
C:\MVN\trucks\src\test\resources
[INFO] [compiler:testCompile {execution: default-testCompile}]

17 Maven - Web | 93

[INFO] No sources to compile


[INFO] [surefire:test {execution: default-test}]
[INFO] No tests to run.
[INFO] [war:war {execution: default-war}]
[INFO] Packaging webapp
[INFO] Assembling webapp[trucks] in [C:\MVN\trucks\target\trucks]
[INFO] Processing war project
[INFO] Copying webapp resources[C:\MVN\trucks\src\main\webapp]
[INFO] Webapp assembled in[77 msecs]
[INFO] Building war: C:\MVN\trucks\target\trucks.war
[INFO] ------------------------------------------------------------------[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------[INFO] Total time: 3 seconds
[INFO] Finished at: Tue Jul 17 11:22:45 IST 2012
[INFO] Final Memory: 11M/85M
[INFO] -------------------------------------------------------------------

Web

C:\ > MVN > trucks > target > trucks.war web webapp
web

Web

URL: http://\<server-name>:\<port-number>/trucks/index.jsp Web

17.2 web page

18
Maven - Elipse IDE

18 Maven - Elipse IDE | 95

Eclipse m2eclipse (http://www.eclipse.org/m2e/) Maven Eclipse

m2eclipse
Eclipse Maven
Eclipse Maven
IDE Maven
Eclipse Maven
Eclipse Maven pom.xml
Maven Eclipse Maven

Maven
Maven pom.xml Maven
Maven

m2eclipse

m2eclipse:

Eclipse

URL

Eclipse 3.5
(Gallileo)

Installing m2eclipse in Eclipse 3.5 (Gallileo) (http://books.sonatype.com/m2eclipse-bo


ok/reference/ch02s03.html)

Eclipse 3.6
(Helios)

Installing m2eclipse in Eclipse 3.6 (Helios) (http://books.sonatype.com/m2eclipse-boo


k/reference/install-sect-marketplace.html)

Eclipse Maven.

Eclipse Maven

Eclipse.
File > Import > option.
Maven Projects Next

18 Maven - Elipse IDE | 96

18.1 Import a maven project in Eclipse.


Maven consumerBank
ing. Maven - () Maven
Finish

18 Maven - Elipse IDE | 97

18.2 Import a maven project in Eclipse.


Eclipse Maven

18 Maven - Elipse IDE | 98

18.3 maven project in Eclipse.


consumerBanking Eclipse Maven

18 Maven - Elipse IDE | 99

18.4 Java Build Path having Maven dependencies.


Eclipse Maven
consumerBanking
Run
maven package
Maven Eclispe
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------[INFO] Building consumerBanking
[INFO]
[INFO] Id: com.companyname.bank:consumerBanking:jar:1.0-SNAPSHOT
[INFO] task-segment: [package]
[INFO] ------------------------------------------------------------------[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.

18 Maven - Elipse IDE | 100

[INFO] [compiler:compile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [surefire:test]
[INFO] Surefire report directory:
C:\MVN\consumerBanking\target\surefire-reports
## ## T E S T SRunning com.companyname.bank.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.047 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] [jar:jar]
[INFO] ------------------------------------------------------------------[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------[INFO] Total time: 1 second
[INFO] Finished at: Thu Jul 12 18:18:24 IST 2012
[INFO] Final Memory: 2M/15M
[INFO] -------------------------------------------------------------------

18 Maven - Elipse IDE | 101

18.5 Run maven command using run as optio


App.java. Run As As Java App.

Hello World!

19
Maven - NetBeans

19 Maven - NetBeans | 103

NetBeans 6.7 Maven


Maven NetBeans 6.9
NetBeans
NetBeans Maven
NetBeans Maven
Maven IDE
NetBeans Maven
NetBeans Maven pom.xml
NetBeans Maven Maven

NetBeans Moven
NetBeans Maven pom.xml
NetBeans Maven Maven
NetBeans Maven

NetBeans Maven

NetBeans.
File Menu > Open Project .
Maven consumerBank
ing. Maven - () Maven

19 Maven - NetBeans | 104

19.1 Open a Maven project in NetBeans.


NetBeans Maven consumerBanking Libraries T
est Libraries. NetBeans Maven

19.2 Maven project in NetBeans.

19 Maven - NetBeans | 105

NetBeans Maven

NetBeans Maven
consumerBanking
"Clean and Build"

19 Maven - NetBeans | 106

19.3 Build a Maven project in NetBeans.


Maven NetBeans log

19 Maven - NetBeans | 107

NetBeans: Executing 'mvn.bat -Dnetbeans.execution=true clean install'


NetBeans:

JAVA_HOME=C:\Program Files\Java\jdk1.6.0_21

## Scanning for projects...Building consumerBanking


##

task-segment: [clean, install][clean:clean]

[resources:resources]
[WARNING] Using platform encoding (Cp1252 actually)
to copy filtered resources, i.e. build is platform dependent!
skip non existing resourceDirectory C:\MVN\consumerBanking\src\main\resources
[compiler:compile]
Compiling 2 source files to C:\MVN\consumerBanking\target\classes
[resources:testResources]
[WARNING] Using platform encoding (Cp1252 actually)
to copy filtered resources, i.e. build is platform dependent!
skip non existing resourceDirectory C:\MVN\consumerBanking\src\test\resources
[compiler:testCompile]
Compiling 1 source file to C:\MVN\consumerBanking\target\test-classes
[surefire:test]
Surefire report directory: C:\MVN\consumerBanking\target\surefire-reports
## ## T E S T SRunning com.companyname.bank.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.023 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[jar:jar]
Building jar: C:\MVN\consumerBanking\target\consumerBanking-1.0-SNAPSHOT.jar
[install:install]
Installing C:\MVN\consumerBanking\target\consumerBanking-1.0-SNAPSHOT.jar
to C:\Users\GB3824\.m2\repository\com\companyname\bank\consumerBanking\
## 1.0-SNAPSHOT\consumerBanking-1.0-SNAPSHOT.jar## BUILD SUCCESSFULTotal time: 9 seconds
Finished at: Thu Jul 19 12:57:28 IST 2012
Final Memory: 16M/85M
------------------------------------------------------------------------

NetBeans

App.java Run File


NetBeans: Executing 'mvn.bat -Dexec.classpathScope=runtime
-Dexec.args=-classpath %classpath com.companyname.bank.App
-Dexec.executable=C:\Program Files\Java\jdk1.6.0_21\bin\java.exe
-Dnetbeans.execution=true process-classes
org.codehaus.mojo:exec-maven-plugin:1.1.1:exec'

19 Maven - NetBeans | 108

NetBeans:

JAVA_HOME=C:\Program Files\Java\jdk1.6.0_21

## Scanning for projects...Building consumerBanking


task-segment: [process-classes,
##

org.codehaus.mojo:exec-maven-plugin:1.1.1:exec][resources:resources]

[WARNING] Using platform encoding (Cp1252 actually)


to copy filtered resources, i.e. build is platform dependent!
skip non existing resourceDirectory C:\MVN\consumerBanking\src\main\resources
[compiler:compile]
Nothing to compile - all classes are up to date
[exec:exec]
## Hello World!## BUILD SUCCESSFULTotal time: 1 second
Finished at: Thu Jul 19 14:18:13 IST 2012
Final Memory: 7M/64M
------------------------------------------------------------------------

20
Maven - IntelliJ IDEA

20 Maven - IntelliJ IDEA | 110

IntelliJ IDEA Maven IntelliJ IDEA Community Edition 11.1

IntelliJ IDEA
IntelliJ IDEA Maven
IntelliJ IDEA Maven
IDE Maven
IntelliJ IDEA Maven
IntelliJ IDEA Maven pom.xml
IntelliJ IDEA Maven Maven

IntelliJ IDEA Moven


IntelliJ IDEA Maven pom.xml
IntelliJ IDEA Maven

IntelliJ IDEA

Maven
IntelliJ IDEA.
File Menu > New Project
import project from existing model

20 Maven - IntelliJ IDEA | 111

20.1 New Project in IntelliJ IDEA, step 1.


Maven

20.2 New Project in IntelliJ IDEA, step 2.

20 Maven - IntelliJ IDEA | 112

Maven consumerBanki
ng. Maven - () Maven

20.3 New Project in IntelliJ IDEA, step 3.


Maven

20 Maven - IntelliJ IDEA | 113

20.4 New Project in IntelliJ IDEA, step 4.


"finish".

20.5 New Project in IntelliJ IDEA, step 5.


IntelliJ IDEA Maven consumerBanking Libraries
Test Libraries. IntelliJ IDEA Maven

20 Maven - IntelliJ IDEA | 114

20.6 Maven project in IntelliJ IDEA.

IntelliJ IDEA Maven

IntelliJ IDEA Maven


consumerBanking
Buid menu > Rebuild Project
IntelliJ IDEA log
4:01:56 PM Compilation completed successfully

20 Maven - IntelliJ IDEA | 115

IntelliJ IDEA

consumerBanking
App.java
Run App.main() .

20 Maven - IntelliJ IDEA | 116

20.7 Maven project in IntelliJ IDEA.


IntelliJ IDEA

20 Maven - IntelliJ IDEA | 117

"C:\Program Files\Java\jdk1.6.0_21\bin\java"
-Didea.launcher.port=7533
"-Didea.launcher.bin.path=
C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 11.1.2\bin"
-Dfile.encoding=UTF-8
-classpath "C:\Program Files\Java\jdk1.6.0_21\jre\lib\charsets.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\deploy.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\javaws.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\jce.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\jsse.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\management-agent.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\plugin.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\resources.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\rt.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\ext\dnsns.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\ext\localedata.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\ext\sunjce_provider.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\ext\sunmscapi.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\ext\sunpkcs11.jar
C:\MVN\consumerBanking\target\classes;
C:\Program Files\JetBrains\
IntelliJ IDEA Community Edition 11.1.2\lib\idea_rt.jar"
com.intellij.rt.execution.application.AppMain com.companyname.bank.App
Hello World!
Process finished with exit code 0


http://wiki.jikexueyuan.com/project/maven/

You might also like