Upload
others
View
3
Download
0
Embed Size (px)
Citation preview
Maven2
Configuration and Build Management
Robert Reiz
PLOIN – Because it's your time Seite 2
A presentation is not a documentation!
A presentation should just support the speaker!
PLOIN – Because it's your time Seite 3
1 – What is Maven2
2 – Short Introduction
3 – Maven2 Advanced
PLOIN – Because it's your time Seite 4
1 What is Maven?
PLOIN – Because it's your time Seite 5
1 – What is Maven?
- Maven exist since 2001.
- Maven2 exist since 2003.
- Maven2 is a completely new development.
- Maven2 is not compatible to Maven1.
- Maven3 is compatible to Maven2.
PLOIN – Because it's your time Seite 6
- A better Ant?
- Project Description / Project Management
- Reporting (Metrics, Code Coverage, Tracking)
- Documentation
- Testing
1 – What is Maven?
PLOIN – Because it's your time Seite 7
- Description of Dependencys
- Convention over Configuration?
- Best Practice
- DRY
- Lifecycle
1 – What is Maven?
PLOIN – Because it's your time Seite 8
/src/ /pom.xml
1 – What is Maven?
PLOIN – Because it's your time Seite 9
/src/ /target/ /pom.xml
1 – What is Maven?
PLOIN – Because it's your time Seite 10
/src/ main/ test/ site/
/pom.xml
1 – What is Maven?
PLOIN – Because it's your time Seite 11
/src/ main/ java/ resources/ webcontent/ test/ site/
/pom.xml
1 – What is Maven?
PLOIN – Because it's your time Seite 12
/src/ main/ java/ resources/ webcontent/ test/ java/ resources/ site/
/pom.xml
1 – What is Maven?
PLOIN – Because it's your time Seite 13
/src/ main/ java/ org.ploin.app.Start.java resources/ webcontent/ test/ java/ org.ploin.app.StartTest.java resources/ site/
/pom.xml
1 – What is Maven?
PLOIN – Because it's your time Seite 14
/src/ main/ java/ org.ploin.app.Start.java resources/ webcontent/ test/ java/ org.ploin.app.StartTest.java resources/ site/
/pom.xml
1 – What is Maven?
PLOIN – Because it's your time Seite 15
<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.mycompany.app</groupId> <artifactId>my-app</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>MyFirstMaven</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project>
1 – What is Maven?
PLOIN – Because it's your time Seite 16
http://repo1.maven.org/maven2/
Commandline command: mvn compile
1 – What is Maven?
PLOIN – Because it's your time Seite 17
~/.m2/repository/
1 – What is Maven?
PLOIN – Because it's your time Seite 18
Lifecycle - Phases
• validate • compile • test • package • integration-test • install • deploy
1 – What is Maven?
PLOIN – Because it's your time Seite 19
Maven Commands:
• mvn compile • mvn test • mvn package • mvn install • mvn eclipse:eclipse • mvn idea:idea • mvn clean
1 – What is Maven?
PLOIN – Because it's your time Seite 20
Maven Packeging:
• ploinMailFactory-1.3.1.jar • ploinMailFactory-1.3.1-javadoc.jar • ploinMailFactory-1.3.1-sources.jar
• ploinMailFactory-1.3.1-jdk5.jar • ploinMailFactory-1.3.1-jdk1.4.jar
1 – What is Maven?
PLOIN – Because it's your time Seite 21
Maven Packeging: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <executions> <execution> <id>attach-sources</id> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <executions> <execution> <id>attach-sources</id> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin>
1 – What is Maven?
PLOIN – Because it's your time Seite 22
Maven Packeging:
mvn -DdownloadJavadocs -DdownloadSources idea:idea
mvn -DdownloadJavadocs –DdownloadSources eclipse:eclipse
1 – What is Maven?
PLOIN – Because it's your time Seite 23
2 Short Introduction
PLOIN – Because it's your time Seite 24
2 – Short Introduction
http://maven.apache.org/
PLOIN – Because it's your time Seite 25
1. Download Zip File.
2. Unzip.
2 – Short Introduction
PLOIN – Because it's your time Seite 26
1. export PATH = $PATH:pathToMaven2/bin
2. export M2_HOME = pathToMaven2
3. export M2 = pathToMaven2/bin
4. export JAVA_HOME = pathToYourJavaHome
2 – Short Introduction
PLOIN – Because it's your time Seite 27
2 – Short Introduction
PLOIN – Because it's your time Seite 28
Quick online introduction: Maven-Quickinstall: http://robert-reiz.com/2008/02/21/maven2-quickinstall-2/ Maven-Quickinstall for Mac OS X: http://robert-reiz.com/2010/10/02/maven2-quickinstall-for-mac-os-x/
2 – Short Introduction
PLOIN – Because it's your time Seite 29
indt
Eclipse-Plugin
PLOIN – Because it's your time Seite 30
2 – Short Introduction
PLOIN – Because it's your time
2 – Short Introduction
PLOIN – Because it's your time
http://m2eclipse.sonatype.org/update/
2 – Short Introduction
PLOIN – Because it's your time
2 – Short Introduction
PLOIN – Because it's your time Seite 34
Maven2 - Import Project into Eclipse
PLOIN – Because it's your time Seite 35
In Project-Root (where the pom.xml is located): mvn eclipse:eclipse!! This command generates Eclipse Metafiles
2 – Short Introduction
PLOIN – Because it's your time
2 – Short Introduction
PLOIN – Because it's your time
2 – Short Introduction
PLOIN – Because it's your time
2 – Short Introduction
PLOIN – Because it's your time
Short Intro: Maven-Quickinstall + Eclipse: http://robert-reiz.com/2008/02/21/maven2-quickinstall-2/
2 – Short Introduction
PLOIN – Because it's your time Seite 40
Live Demo
PLOIN – Because it's your time Seite 41
3 Maven2 Advanced
PLOIN – Because it's your time Seite 42
3 – Maven2 Advanced
Dependencies & Exclusions
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-hibernate3</artifactId> <version>[2.0.8,)</version> <scope>compile</scope> <exclusions> <exclusion> <groupId>org.hibernate</groupId> <artifactId>hibernate</artifactId> </exclusion> </exclusions>
</dependency>
PLOIN – Because it's your time Seite 43
Dependencies – version ranges
<version>[1.0,)</version> -> always the newest version
<version>(,1.0],[1.2,)</version> -> everything but not 1.1
<version>[1.0,2.0]</version> -> everything from 1.0 to 2.0
3 – Maven2 Advanced
PLOIN – Because it's your time Seite 44
Maven through Proxies
<settings> . . <proxies> <proxy> <active>true</active> <protocol>http</protocol>
<host>proxy.somewhere.com</host> <port>8080</port> <username>proxyuser</username> <password>somepassword</password> <nonProxyHosts>www.google.com|*.somewhere.com</nonProxyHosts> </proxy> </proxies> . .
</settings>
3 – Maven2 Advanced
PLOIN – Because it's your time Seite 45
Your own M2 Repository Server
3 – Maven2 Advanced
PLOIN – Because it's your time Seite 46
3 – Maven2 Advanced
PLOIN – Because it's your time Seite 47
Archetypes
3 – Maven2 Advanced
PLOIN – Because it's your time Seite 48
mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.mycompany.app -DartifactId=my-app
mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp -DgroupId=com.mycompany.app -DartifactId=my-webapp
3 – Maven2 Advanced
PLOIN – Because it's your time Seite 49
http://robert-reiz.com/tutorials/archetypes/
3 – Maven2 Advanced
PLOIN – Because it's your time Seite 50
Archetypes Demo
PLOIN – Because it's your time Seite 51
PLOIN – Because it's your time Seite 52
? ? ?