exigen services confidential apache maven 2 overview getting started with apache maven 2 25 december...

42
Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 June 18, 2022

Upload: jewel-lloyd

Post on 21-Jan-2016

251 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential Exigen Services confidential

Apache Maven 2 Overview

Getting started with Apache Maven 2

April 21, 2023

Page 2: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

The Goal

• Understand Maven principles

• Build project with Maven

• Compare to Apache Ant

2

Page 3: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

GETTING STARTED

What is Maven?

3

Page 4: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

Glossary

• Artifact

• Maven repository

• Dependency

4

Page 5: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

What is Maven?

• Open Source: Apache License 2.0

• Uniform build system

• Knowledge accumulator

• Project management tool

• Declarative logic instead of imperative

5

Page 6: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

Maven help us

• Build

• Dependencies

• Quality project info

• Release

6

Page 7: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

CORE MAVEN 2

Change your mind

7

Page 8: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

Maven project

pom.xml

source code

generatedcode

resources binaryfiles

RepositoriesProject lifecycleProject lifecycle

plug-inplug-in plug-inplug-in plug-inplug-in

Project Object Model

Project Object Model

DependencyManager

DependencyManager

8

Page 9: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

groupIdartifactIdversiontype

groupIdartifactIdversiontype

Project Object Model (pom.xml)

• Identification

• Hierarchy

• Structure

• Dependencies

• Build settings

my-appmy-app

parentparent

another-appanother-app

Spring2.5.6

Spring2.5.6

Junit4.5

Junit4.5

ServletAPI2.5

ServletAPI2.5

my-appmy-app

9

project homeproject home

sourcessources

classesclasses

etc.etc.

Page 10: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

Super POM

• Package: jar

• Default project structure

• Default artifacts Repository

• Release profile

10

Page 11: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

Default folders structure

11

Page 12: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

Maven does your work

• Store your stuff only

• Maven knows what you need

• Dependencies are stored in shared repository

12

Page 13: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

Dependency scope

ResultScope

Compile classpath

Result package

Test classpath

Lookup repository

compile + + + +

provided + - + +

runtime - + + +

test - - + +

system + - + -

13

Page 14: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

Transitive dependencies

my-appmy-app

dependency.1dependency.1 dependency.2dependency.2 dependency.3dependency.3

dependency.1.1dependency.1.1 dependency.1.2dependency.1.2

14

Page 15: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

Transitive dependency scope

15

our dependency

dependency of our dependency

result scope of 3rd party dependency

Page 16: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

Maven Repository

User workstation Local network Internet

internal external

Central (default)

Local repositoryLocal repository External repositoriesExternal repositories

user local

16

Page 17: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

Build lifecycle

1. validate

2. compile

3. test

4. package

5. verify

6. install

7. deploy

17

check pom.xml

compile the source

run unit tests

create jar/war/...

verify the package

publish package to local repo

publish package to remote repo

Page 18: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

MAVEN IN ACTION

Simple Maven project example

18

Page 19: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

Installation

1. Requirements:• JRE/JDK 1.4 or higher

2. Download

3. Unzip

4. Setup environment variables:• M2_HOME• M2• PATH

5. Enjoy

19

Page 20: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

Configuration

• Global• <M2_HOME>/conf/settings.xml

• User local• <USER_HOME>/.m2/settings.xml

20

Page 21: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

settings.xml

• Path to local repository

• Proxy

• Repository mirrors

• Servers authentication

• Profiles

• Other Maven 2 configurations

21

Page 22: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

Configuration - Proxy

<settings>

<proxies>

<proxy>

<active>true</active>

<protocol>http</protocol>

<host>cache</host>

<port>3128</port>

</proxy>

</proxies>

</settings>

22

Page 23: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

• mvn [goal(s)] [phase(s)] [options]• mvn compile:compile• mvn install• mvn install –X –DsomeProperty=10

mvn

23

mvn <plugin>:<goal>mvn <plugin>:<goal>

mvn <phase name>mvn <phase name>

Page 24: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

Start-up new project

mvn archetype:create

-DarchetypeGroupId=org.apache.maven.archetypes

-DgroupId=com.exigenservices.training

-DartifactId=myjsf

24

Result:

• Default folder structure• pom.xml• First java class• First unit-test class

Page 25: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

pom.xml: Minimal POM

<project>

<modelVersion>4.0.0</modelVersion>

<groupId>com.exigenservices.app</groupId>

<artifactId>my-app</artifactId>

<version>SNAPSHOT</version>

</project>

25

Page 26: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

pom.xml: Dependencies

<project>

<dependencies>

<dependency>

<groupId>junit</groupId>

<artifactId>junit</artifactId>

<version>4.6</version>

<scope>test</scope>

</dependency>

</dependencies>

</project>

26

Page 27: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

Add repository

<project>

<repositories>

<repository>

<id>Jboss.repository</id>

<url>

http://repository.jboss.org/maven2

</url>

</repository>

</repositories>

</project>

27

Page 28: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

pom.xml: Plug-ins configuration

<project>

<build>

<plugins>

<plugin>

<artifactId>maven-compiler-plugin</artifactId>

<configuration>

<source>1.5</source>

<target>1.5</target>

</configuration>

</plugin>

</plugins>

</build>

</project>

28

Page 29: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

Build project

29

• mvn install

1. validate

2. compile

3. test

4. package

5. install

Page 30: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

Install and Deploy

30

installinstall

Local network Internet

deploydeploy

Page 31: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

When deploy is needed?

• Release

• Update snapshot• available for other projects

31

Page 32: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

IDE INTEGRATION

Develop with pleasure!

32

Page 33: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

IDE list

• InteliJ IDEA from 7.0

• Eclipse

• NetBeans 6.5

33

Page 34: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

NetBeans

• Embedded

• Basic features

• Weak Dependency Management

34

Page 35: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

Eclipse

• Plug-in “m2eclipse”

• All necessary features

• Dependency synchronization

• POM visual editor

• Lifecycle build runners

35

Page 36: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

InteliJ IDEA

• Embedded from 7.0

• All Necessary Features

• Dependency synchronization

• XML editor for POM

• Lifecycle build runners

36

Page 37: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

CONCLUSION

Let’s summarize

37

Page 38: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

Advantages (vs. Ant)

• Know Maven – can build project

• Dependency management

• Less CM activities

• Force to standardization

• Readable pom.xml

• High reusability

38

Page 39: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

Disadvantages (vs. Ant)

• Understanding

• Artifacts search

• Plug-ins documentation

• “Exotic things” - maven-ant-plugin

• Difficult to move from Ant

39

Page 40: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

Maven repositories

• Central http://repo1.maven.org/maven2/

• Central repository Explorer http://mvnrepository.com

• Collection of plugins for Maven 2 http://mojo.codehaus.org

• JBoss http://repository.jboss.com/maven2/

• Sun http://download.java.net/maven/2/

• Atlassian http://repository.atlassian.com/maven2/

40

Page 41: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

References

• Maven site http://maven.apache.org

• Quick guide http://maven.apache.org/guides/MavenQuickReferenceCard.pdf

• Maven FAQhttp://docs.codehaus.org/display/MAVENUSER/FAQs-1

• Maven: The Definitive Guidehttp://www.sonatype.com/node/158?file=books/maven-definitive-

guide.pdf

• Maven overview in Russian http://www.ibm.com/developerworks/ru/edu/j-mavenv2/index.html

• m2eclipse plug-inhttp://m2eclipse.codehaus.org

41

Page 42: Exigen Services confidential Apache Maven 2 Overview Getting started with Apache Maven 2 25 December 2015

Exigen Services confidential

QUESTIONS

Now it’s your turn…

42