SlideShare une entreprise Scribd logo
1  sur  34
Basic Maven Chris Roeder Kevin Livingston April 2011 5/5/11 1 Chris Roeder, Kevin Livingston
Maven Big Picture: Builds: Maven will compile your code and assemble jars. (similar to ant’s function) Dependency Management: Maven will fetch other jars your project uses and assemble a CLASSPATH for the compiler. (similar to ivy’s function) Integrate with Eclipse: by way of plugins like m2. The goal of this talk is to get you started, not to make an expert of you.  5/5/11 Chris Roeder, Kevin Livingston 2
Contents Introduction Dependency Manangement Builds and pom files Modules Repositories Releases and Snapshots Mojo: Plugins, Goals, Phases Runtime Review, Advanced Topics, Caution Thanks 5/5/11 Chris Roeder, Kevin Livingston 3
Introduction 1 Dependency Manager:Given a description of dependent jars, Maven will fetch them for you Build  Tool: Convention over ConfigurationIf your project follows a standard layout, things just work (with no ant files) Running: Maven will assemble as classpath for you at runtime. Consider what this means for deployment. 5/5/11 4 Chris Roeder, Kevin Livingston
Introduction 2 Maven is organized around projects that produce a single jar.(or sets of projects that each produce a jar) Each project has a pom.xml file, a “pom”, that configures it. The pom describes the project and its dependencies. Each with 3 “coordinates”: Group ID		(edu.ucdenver.ccp) Artifact ID 		(common) Version 			(1.0) 5/5/11 5 Chris Roeder, Kevin Livingston
Introduction: Convention over Configuration A big Maven philosophy is that life is easier with clear conventions: You know what to expect The tool knows what to expect, so… …it can run with little configuration. Made popular by Ruby on Rails, and others. Conventions (defaults) are declared in a (mostly) invisible “super pom” 5/5/11 6 Chris Roeder, Kevin Livingston
Dependency Management Maven is declarative (not imperative): Specify the jars used, where they come from, and what release, and Maven will manage the files without explicit coding. Maven manages the files. You don’t need a “lib” directory …even in eclipse. No modifying the project’s classpath. 5/5/11 7 Chris Roeder, Kevin Livingston
Dependency Management: Adding a new jar  Google “maven junit” to find the dependency for junit. Add this to your pom.xml (maven file): <dependency>		<groupId>junit</groupId>		<artifactId>junit</artifactId>		<version>4.8.2</version></dependency> Even if the jar filename has no version, Maven keeps track. Pom search engines include: http://mvnrepository.com/ 5/5/11 8 Chris Roeder, Kevin Livingston
Dependency Management:Finding the Jar Most jars are in “The” repository, a public central repository for community use. Sometimes the are not, so tell Maven about other repositories: <repository> 	<name>Clojure main release repository</name><id>clojure-releases</id>   <url>http://build.clojure.org/releases</url> </repository> You can usually find this in the same place as the dependency you Googled. 5/5/11 9 Chris Roeder, Kevin Livingston
5/5/11 Chris Roeder, Kevin Livingston 10
5/5/11 Chris Roeder, Kevin Livingston 11
Build Tool By default, Maven:  knows where to find the code and resources.  You told it where and what the dependent jars are. Convention tells it where the new jar should go and what it should be named. Runs the “install” goal, making a jar available to more maven process. (more about goals coming) 5/5/11 12 Chris Roeder, Kevin Livingston
Example POM <?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/maven-v4_0_0.xsd"> <properties>	<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><modelVersion>4.0.0</modelVersion><groupId>edu.ucdenver.ccp</groupId><artifactId>common</artifactId><packaging>jar</packaging><version>1.0-SNAPSHOT</version> <name>${project.artifactId}</name> <description>ccp common code</description> 5/5/11 13 Chris Roeder, Kevin Livingston Project “Coordinates”
Example POM (cont) <project> …<dependencies>		<dependency>			<groupId>log4j</groupId>			<artifactId>log4j</artifactId>			<version>1.2.12</version>		</dependency>		<dependency>			<groupId>junit</groupId>			<artifactId>junit</artifactId>			<version>4.8.2</version>			<scope>test</scope>		</dependency> 		</dependencies></project> 5/5/11 14 Chris Roeder, Kevin Livingston
Example POM: Repository Stanza <repositories>  <repository><id>apache incudbaor</id><name>apache-incubator</name><url>http://people.apache.org/repo/m2-incubating-repository/</url>  </repository>  <repository><id>cleartk-googlecode</id>	<name>ClearTK Google Code repository</name>	<url>http://cleartk.googlecode.com/svn/repo</url>	<snapshots><enabled>true</enabled>	</snapshots>  </repository></repositories> 5/5/11 15 Chris Roeder, Kevin Livingston
Build Tool: unconventional If you must work in a directory structure that doesn’t follow the convention… …just tell it where to find things:  <build>		<sourceDirectory>src</sourceDirectory>		<resources>			<resource>				<directory>resources</directory>			</resource>		</resources></build> Maven rhetoric “highly discourages” this, but it doesn’t seem to be an issue. 5/5/11 16 Chris Roeder, Kevin Livingston
Modules:Families of Projects You can have a “super project” that binds a number of sub-projects together.  A directory and a pom. The directory can sit besides the others. The pom goes in it.<?xml version="1.0" encoding="UTF-8"?><project>	<modelVersion>4.0.0</modelVersion>	<groupId>SciKnowMine</groupId>	<artifactId>SciKnowMine</artifactId>	<version>0.0.2-SNAPSHOT</version>	<packaging>pom</packaging>	<modules>		<module>../SciKnowMineCore</module>		<module>../SciKnowMineCitationStore</module>		<module>../SciKnowMineTriage</module>		<module>../SciKnowMinePreProcessing</module>	</modules></project> Allows you to run them all from this one directory. 5/5/11 17 Chris Roeder, Kevin Livingston
Parent Pom A parent pom may be declared for each module that specifies common resources, dependencies, properties, etc. The parent looks normal. Children declare it as a parent: 	<parent>		<groupId>edu.ucdenver.ccp</groupId>		<artifactId>kr</artifactId>		<version>1.0-SNAPSHOT</version></parent> Can be combined with main module from previous slide. 5/5/11 Chris Roeder, Kevin Livingston 18
Properties Not called “variable” because they aren’t Declare them: 	<properties> 			<clojure.version>1.2.0</clojure.version>		<ver.jena>2.6.3</ver.jena>		<ver.arq>2.8.5</ver.arq>		<ver.sesame>2.3.2</ver.sesame></properties> Use them: <dependency>		<groupId>org.clojure</groupId>		<artifactId>clojure</artifactId>		<version>${clojure.version}</version></dependency> 5/5/11 Chris Roeder, Kevin Livingston 19
Repositories Maven uses three levels of repositories: Reactor: not really a repository. It’s part of a particular run. Install: your personal repository: ~/.m2/repository Deploy: something like a web server of jars They are used sequentially: if an artifact (jar) is not available in the Reactor, it looks in your ~/.m2. If not there, it searches for deployments in repositories.  Really, there are two kinds of Deployment repositories: You company’s local, private one, that caches. Globally available repositories where things are publicly available. The local repository also hosts “in-house” code. 5/5/11 20 Chris Roeder, Kevin Livingston
Artifactory Artifactory is the Maven repository implementation used here: http://amc-bakeoff.ucdenver.pvt:8081 It’s used to cache artifacts (jars) from other repositories to reduce network load and load on those community repositories. It also hosts locally developed artifacts. 5/5/11 21 Chris Roeder, Kevin Livingston
Snapshots Maven doesn’t deal strictly with perfectly prepared releases. Snapshots are a way of sharing a work-in-progress. If you specify a dependency as a snapshot, you get the latest and greatest: the most recently published. The Maven repositories deal with keeping track of them and which is the most recent. You can fix on a particular snapshot by referring to it using it’s timestamp. 5/5/11 22 Chris Roeder, Kevin Livingston
Snapshots 2 A snapshot’s version says “SNAPSHOT”: 	<version>0.0.2-SNAPSHOT</version> A repository has to be marked as one that holds snapshots: <repository>		<id>clojure-snapshots</id>		<url>http://build.clojure.org/snapshots</url>		<snapshots><enabled>true</enabled>		</snapshots>	</repository> Dependencies too: <dependency>		<groupId>swank-clojure</groupId>		<artifactId>swank-clojure</artifactId><version>1.3.0-SNAPSHOT</version></dependency> 5/5/11 Chris Roeder, Kevin Livingston 23
Plugins Maven uses plugins to add functionality. They are retreived like other artifacts: from repositories. They are configured in stanzas called “plugin” Their commands start with the plugin name: Exec:java, for example is the exec plugin’s java goal Plugin goals are called “Mojo” in Maven 5/5/11 24 Chris Roeder, Kevin Livingston
Example Plugin Stanza <plugin><groupId>org.apache.maven.plugins</groupId>	<artifactId>maven-compiler-plugin</artifactId>	<version>2.0.2</version>	<configuration><source>1.6</source><target>1.6</target>	</configuration></plugin> 5/5/11 25 Chris Roeder, Kevin Livingston
Mojo:Maven CommandsGoals Maven is implemented in a number of plugins. Each plugin has one or more goals (commands) giving your install some kind of “mojo” Goals are executed by naming them and their plugin: 	<plugin>:<goal> mvnarchetype:generate Maven groups goals can be associated with “lifecycle phases”, and run simply by naming a phase mvninstall 5/5/11 26 Chris Roeder, Kevin Livingston
Maven Phases A phase can have zero or more goals associated with it. A lifecycle is a series of phases leading up to a package type. Phases are ordered, and require successful completion of prior phases. The default lifecycle is for jars, and consists of phases that run the following goals: 5/5/11 Chris Roeder, Kevin Livingston 27
Runtime Tool A plugin, exec, allows you to call java from Maven so you can use the classpath assembly features to run. Consider what possibilities this creates: Deliver a running project with just one file: the pom. 5/5/11 28 Chris Roeder, Kevin Livingston
Runtime 2: The getResourceAsStream Soap Box Not all projects remain naïve of the file system. Some expect to be able to open files using either absolute or relative filepaths and the File class.  These files can’t be buried in a jar file. Use maven-assembly-pack to build a deployment assemply. Unpack with maven-dependency-unpack. 5/5/11 Chris Roeder, Kevin Livingston 29
Review: Maven Vocabulary Project Pom – a file that tells maven about a particular project. Artifact – a jar, war, pom or other thing required by a project Dependency – something your project needs from another project. Coordinates – the comination of attributes that identify an artifact Repository – a place for artifacts. Lifecycle – a series of steps to produce an artifact. Phase – one of the steps in a Lifecycle. Plugin (Mojo) – added capability Install – putting an artifact into your local ~/.m2/repository Deploy – putting an artifact into a repository Reactor – a process that analyzes and resolves dependencies and runs the build. It is the innermost (if temporary) container of artifacts. 5/5/11 Chris Roeder, Kevin Livingston 30
Review: Standard Directory Layout (with UIMA additions) http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html src main Java edu.isi.bmkeg… Resources desc/ae desc/cpe desc/cr typeSystem models test java resources target Product-0.1-SNAPSHOT.jar (created by build run) 5/5/11 Chris Roeder, Kevin Livingston 31
Advanced Topics(not covered here) Archetypes are a way of building a template for maven templates (poms). Maven does a lot in terms of Dependency Management: What if you have 2 jars that each depend on a third jar, but different versions? Maven picks the most recent, but this assumes backward compatibility. Scope: items within maven can be scoped to a phase, so for example, jUnit doesn’t have to ship with the production jar. SCM integration: How does this integrate with Subversion? Eclipse Integration: m2 eclipse plugin Site Utilities: a project info web site can be built that includes author and test info. among others. 5/5/11 Chris Roeder, Kevin Livingston 32
Caution The learning curve can be steep. Be patient: you’ll write less SCM code. Follow Convention. Don’t be afraid to violate Convention. Get a second opinion. Read the errors bottom-up. Run “mvn clean” and “rm ~/.m2/repository” when things get real weird. http://www.sonatype.com/books/mvnex-book/reference/public-book.html 5/5/11 33 Chris Roeder, Kevin Livingston
Thank You Hunter Lab Software Engineers for keeping the bar high: Bill Baumgartner Yuriy Malenkiy ISI’s SciKnowMine project for using tools that practically require Maven: Cartic Ramakrishnan Gully Burns 5/5/11 34 Chris Roeder, Kevin Livingston

Contenu connexe

Tendances (20)

Maven tutorial
Maven tutorialMaven tutorial
Maven tutorial
 
Maven 2 features
Maven 2 featuresMaven 2 features
Maven 2 features
 
Maven Overview
Maven OverviewMaven Overview
Maven Overview
 
Demystifying Maven
Demystifying MavenDemystifying Maven
Demystifying Maven
 
Hands On with Maven
Hands On with MavenHands On with Maven
Hands On with Maven
 
Using Maven 2
Using Maven 2Using Maven 2
Using Maven 2
 
Maven Introduction
Maven IntroductionMaven Introduction
Maven Introduction
 
An introduction to Maven
An introduction to MavenAn introduction to Maven
An introduction to Maven
 
Maven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafeMaven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafe
 
Maven Basics - Explained
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - Explained
 
Maven basics
Maven basicsMaven basics
Maven basics
 
Maven ppt
Maven pptMaven ppt
Maven ppt
 
Apache maven 2 overview
Apache maven 2 overviewApache maven 2 overview
Apache maven 2 overview
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
Maven
MavenMaven
Maven
 
Maven for Dummies
Maven for DummiesMaven for Dummies
Maven for Dummies
 
Maven
Maven Maven
Maven
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
Maven 2 Introduction
Maven 2 IntroductionMaven 2 Introduction
Maven 2 Introduction
 
Apache Maven In 10 Slides
Apache Maven In 10 SlidesApache Maven In 10 Slides
Apache Maven In 10 Slides
 

Similaire à Maven

Maven 2.0 - Improve your build patterns
Maven 2.0 - Improve your build patternsMaven 2.0 - Improve your build patterns
Maven 2.0 - Improve your build patternselliando dias
 
Maven with Flex
Maven with FlexMaven with Flex
Maven with FlexPriyank
 
Maven with Flex
Maven with FlexMaven with Flex
Maven with FlexPriyank
 
S/W Design and Modularity using Maven
S/W Design and Modularity using MavenS/W Design and Modularity using Maven
S/W Design and Modularity using MavenScheidt & Bachmann
 
Maven 2.0 - Project management and comprehension tool
Maven 2.0 - Project management and comprehension toolMaven 2.0 - Project management and comprehension tool
Maven 2.0 - Project management and comprehension toolelliando dias
 
Apache Maven - eXo VN office presentation
Apache Maven - eXo VN office presentationApache Maven - eXo VN office presentation
Apache Maven - eXo VN office presentationArnaud Héritier
 
maven-for-maine-jug-090226091601-phpapp02.ppt
maven-for-maine-jug-090226091601-phpapp02.pptmaven-for-maine-jug-090226091601-phpapp02.ppt
maven-for-maine-jug-090226091601-phpapp02.pptnikhilmahendranath1
 
Introduction to Maven for beginners and DevOps
Introduction to Maven for beginners and DevOpsIntroduction to Maven for beginners and DevOps
Introduction to Maven for beginners and DevOpsSISTechnologies
 
Java, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorialJava, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorialRaghavan Mohan
 
Maven: Managing Software Projects for Repeatable Results
Maven: Managing Software Projects for Repeatable ResultsMaven: Managing Software Projects for Repeatable Results
Maven: Managing Software Projects for Repeatable ResultsSteve Keener
 
Simple ways to add and work with a `.jar` file in your local maven setup
Simple ways to add and work with a `.jar` file in your local maven setupSimple ways to add and work with a `.jar` file in your local maven setup
Simple ways to add and work with a `.jar` file in your local maven setupAlan Richardson
 
Apache maven, a software project management tool
Apache maven, a software project management toolApache maven, a software project management tool
Apache maven, a software project management toolRenato Primavera
 

Similaire à Maven (20)

Maven 2.0 - Improve your build patterns
Maven 2.0 - Improve your build patternsMaven 2.0 - Improve your build patterns
Maven 2.0 - Improve your build patterns
 
Maven with Flex
Maven with FlexMaven with Flex
Maven with Flex
 
Maven with Flex
Maven with FlexMaven with Flex
Maven with Flex
 
Maven
MavenMaven
Maven
 
S/W Design and Modularity using Maven
S/W Design and Modularity using MavenS/W Design and Modularity using Maven
S/W Design and Modularity using Maven
 
A-Z_Maven.pdf
A-Z_Maven.pdfA-Z_Maven.pdf
A-Z_Maven.pdf
 
Exploring Maven SVN GIT
Exploring Maven SVN GITExploring Maven SVN GIT
Exploring Maven SVN GIT
 
Apache Maven
Apache MavenApache Maven
Apache Maven
 
Maven 2.0 - Project management and comprehension tool
Maven 2.0 - Project management and comprehension toolMaven 2.0 - Project management and comprehension tool
Maven 2.0 - Project management and comprehension tool
 
Apache Maven - eXo VN office presentation
Apache Maven - eXo VN office presentationApache Maven - eXo VN office presentation
Apache Maven - eXo VN office presentation
 
Mavenppt
MavenpptMavenppt
Mavenppt
 
Maven in Mule
Maven in MuleMaven in Mule
Maven in Mule
 
maven-for-maine-jug-090226091601-phpapp02.ppt
maven-for-maine-jug-090226091601-phpapp02.pptmaven-for-maine-jug-090226091601-phpapp02.ppt
maven-for-maine-jug-090226091601-phpapp02.ppt
 
Introduction to Maven for beginners and DevOps
Introduction to Maven for beginners and DevOpsIntroduction to Maven for beginners and DevOps
Introduction to Maven for beginners and DevOps
 
Java, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorialJava, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorial
 
Maven: Managing Software Projects for Repeatable Results
Maven: Managing Software Projects for Repeatable ResultsMaven: Managing Software Projects for Repeatable Results
Maven: Managing Software Projects for Repeatable Results
 
Simple ways to add and work with a `.jar` file in your local maven setup
Simple ways to add and work with a `.jar` file in your local maven setupSimple ways to add and work with a `.jar` file in your local maven setup
Simple ways to add and work with a `.jar` file in your local maven setup
 
Apache maven, a software project management tool
Apache maven, a software project management toolApache maven, a software project management tool
Apache maven, a software project management tool
 
Liferay maven sdk
Liferay maven sdkLiferay maven sdk
Liferay maven sdk
 
Using Maven2
Using Maven2Using Maven2
Using Maven2
 

Plus de Chris Roeder

Plus de Chris Roeder (7)

Roeder posterismb2010
Roeder posterismb2010Roeder posterismb2010
Roeder posterismb2010
 
Roeder rocky 2011_46
Roeder rocky 2011_46Roeder rocky 2011_46
Roeder rocky 2011_46
 
Uml
UmlUml
Uml
 
Spring survey
Spring surveySpring survey
Spring survey
 
Rocky2010 roeder full_textbiomedicalliteratureprocesing
Rocky2010 roeder full_textbiomedicalliteratureprocesingRocky2010 roeder full_textbiomedicalliteratureprocesing
Rocky2010 roeder full_textbiomedicalliteratureprocesing
 
Sge
SgeSge
Sge
 
Hibernate
HibernateHibernate
Hibernate
 

Dernier

SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 

Dernier (20)

SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 

Maven

  • 1. Basic Maven Chris Roeder Kevin Livingston April 2011 5/5/11 1 Chris Roeder, Kevin Livingston
  • 2. Maven Big Picture: Builds: Maven will compile your code and assemble jars. (similar to ant’s function) Dependency Management: Maven will fetch other jars your project uses and assemble a CLASSPATH for the compiler. (similar to ivy’s function) Integrate with Eclipse: by way of plugins like m2. The goal of this talk is to get you started, not to make an expert of you. 5/5/11 Chris Roeder, Kevin Livingston 2
  • 3. Contents Introduction Dependency Manangement Builds and pom files Modules Repositories Releases and Snapshots Mojo: Plugins, Goals, Phases Runtime Review, Advanced Topics, Caution Thanks 5/5/11 Chris Roeder, Kevin Livingston 3
  • 4. Introduction 1 Dependency Manager:Given a description of dependent jars, Maven will fetch them for you Build Tool: Convention over ConfigurationIf your project follows a standard layout, things just work (with no ant files) Running: Maven will assemble as classpath for you at runtime. Consider what this means for deployment. 5/5/11 4 Chris Roeder, Kevin Livingston
  • 5. Introduction 2 Maven is organized around projects that produce a single jar.(or sets of projects that each produce a jar) Each project has a pom.xml file, a “pom”, that configures it. The pom describes the project and its dependencies. Each with 3 “coordinates”: Group ID (edu.ucdenver.ccp) Artifact ID (common) Version (1.0) 5/5/11 5 Chris Roeder, Kevin Livingston
  • 6. Introduction: Convention over Configuration A big Maven philosophy is that life is easier with clear conventions: You know what to expect The tool knows what to expect, so… …it can run with little configuration. Made popular by Ruby on Rails, and others. Conventions (defaults) are declared in a (mostly) invisible “super pom” 5/5/11 6 Chris Roeder, Kevin Livingston
  • 7. Dependency Management Maven is declarative (not imperative): Specify the jars used, where they come from, and what release, and Maven will manage the files without explicit coding. Maven manages the files. You don’t need a “lib” directory …even in eclipse. No modifying the project’s classpath. 5/5/11 7 Chris Roeder, Kevin Livingston
  • 8. Dependency Management: Adding a new jar Google “maven junit” to find the dependency for junit. Add this to your pom.xml (maven file): <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.2</version></dependency> Even if the jar filename has no version, Maven keeps track. Pom search engines include: http://mvnrepository.com/ 5/5/11 8 Chris Roeder, Kevin Livingston
  • 9. Dependency Management:Finding the Jar Most jars are in “The” repository, a public central repository for community use. Sometimes the are not, so tell Maven about other repositories: <repository> <name>Clojure main release repository</name><id>clojure-releases</id> <url>http://build.clojure.org/releases</url> </repository> You can usually find this in the same place as the dependency you Googled. 5/5/11 9 Chris Roeder, Kevin Livingston
  • 10. 5/5/11 Chris Roeder, Kevin Livingston 10
  • 11. 5/5/11 Chris Roeder, Kevin Livingston 11
  • 12. Build Tool By default, Maven: knows where to find the code and resources. You told it where and what the dependent jars are. Convention tells it where the new jar should go and what it should be named. Runs the “install” goal, making a jar available to more maven process. (more about goals coming) 5/5/11 12 Chris Roeder, Kevin Livingston
  • 13. Example POM <?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/maven-v4_0_0.xsd"> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><modelVersion>4.0.0</modelVersion><groupId>edu.ucdenver.ccp</groupId><artifactId>common</artifactId><packaging>jar</packaging><version>1.0-SNAPSHOT</version> <name>${project.artifactId}</name> <description>ccp common code</description> 5/5/11 13 Chris Roeder, Kevin Livingston Project “Coordinates”
  • 14. Example POM (cont) <project> …<dependencies> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.12</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.2</version> <scope>test</scope> </dependency> </dependencies></project> 5/5/11 14 Chris Roeder, Kevin Livingston
  • 15. Example POM: Repository Stanza <repositories> <repository><id>apache incudbaor</id><name>apache-incubator</name><url>http://people.apache.org/repo/m2-incubating-repository/</url> </repository> <repository><id>cleartk-googlecode</id> <name>ClearTK Google Code repository</name> <url>http://cleartk.googlecode.com/svn/repo</url> <snapshots><enabled>true</enabled> </snapshots> </repository></repositories> 5/5/11 15 Chris Roeder, Kevin Livingston
  • 16. Build Tool: unconventional If you must work in a directory structure that doesn’t follow the convention… …just tell it where to find things: <build> <sourceDirectory>src</sourceDirectory> <resources> <resource> <directory>resources</directory> </resource> </resources></build> Maven rhetoric “highly discourages” this, but it doesn’t seem to be an issue. 5/5/11 16 Chris Roeder, Kevin Livingston
  • 17. Modules:Families of Projects You can have a “super project” that binds a number of sub-projects together. A directory and a pom. The directory can sit besides the others. The pom goes in it.<?xml version="1.0" encoding="UTF-8"?><project> <modelVersion>4.0.0</modelVersion> <groupId>SciKnowMine</groupId> <artifactId>SciKnowMine</artifactId> <version>0.0.2-SNAPSHOT</version> <packaging>pom</packaging> <modules> <module>../SciKnowMineCore</module> <module>../SciKnowMineCitationStore</module> <module>../SciKnowMineTriage</module> <module>../SciKnowMinePreProcessing</module> </modules></project> Allows you to run them all from this one directory. 5/5/11 17 Chris Roeder, Kevin Livingston
  • 18. Parent Pom A parent pom may be declared for each module that specifies common resources, dependencies, properties, etc. The parent looks normal. Children declare it as a parent: <parent> <groupId>edu.ucdenver.ccp</groupId> <artifactId>kr</artifactId> <version>1.0-SNAPSHOT</version></parent> Can be combined with main module from previous slide. 5/5/11 Chris Roeder, Kevin Livingston 18
  • 19. Properties Not called “variable” because they aren’t Declare them: <properties> <clojure.version>1.2.0</clojure.version> <ver.jena>2.6.3</ver.jena> <ver.arq>2.8.5</ver.arq> <ver.sesame>2.3.2</ver.sesame></properties> Use them: <dependency> <groupId>org.clojure</groupId> <artifactId>clojure</artifactId> <version>${clojure.version}</version></dependency> 5/5/11 Chris Roeder, Kevin Livingston 19
  • 20. Repositories Maven uses three levels of repositories: Reactor: not really a repository. It’s part of a particular run. Install: your personal repository: ~/.m2/repository Deploy: something like a web server of jars They are used sequentially: if an artifact (jar) is not available in the Reactor, it looks in your ~/.m2. If not there, it searches for deployments in repositories. Really, there are two kinds of Deployment repositories: You company’s local, private one, that caches. Globally available repositories where things are publicly available. The local repository also hosts “in-house” code. 5/5/11 20 Chris Roeder, Kevin Livingston
  • 21. Artifactory Artifactory is the Maven repository implementation used here: http://amc-bakeoff.ucdenver.pvt:8081 It’s used to cache artifacts (jars) from other repositories to reduce network load and load on those community repositories. It also hosts locally developed artifacts. 5/5/11 21 Chris Roeder, Kevin Livingston
  • 22. Snapshots Maven doesn’t deal strictly with perfectly prepared releases. Snapshots are a way of sharing a work-in-progress. If you specify a dependency as a snapshot, you get the latest and greatest: the most recently published. The Maven repositories deal with keeping track of them and which is the most recent. You can fix on a particular snapshot by referring to it using it’s timestamp. 5/5/11 22 Chris Roeder, Kevin Livingston
  • 23. Snapshots 2 A snapshot’s version says “SNAPSHOT”: <version>0.0.2-SNAPSHOT</version> A repository has to be marked as one that holds snapshots: <repository> <id>clojure-snapshots</id> <url>http://build.clojure.org/snapshots</url> <snapshots><enabled>true</enabled> </snapshots> </repository> Dependencies too: <dependency> <groupId>swank-clojure</groupId> <artifactId>swank-clojure</artifactId><version>1.3.0-SNAPSHOT</version></dependency> 5/5/11 Chris Roeder, Kevin Livingston 23
  • 24. Plugins Maven uses plugins to add functionality. They are retreived like other artifacts: from repositories. They are configured in stanzas called “plugin” Their commands start with the plugin name: Exec:java, for example is the exec plugin’s java goal Plugin goals are called “Mojo” in Maven 5/5/11 24 Chris Roeder, Kevin Livingston
  • 25. Example Plugin Stanza <plugin><groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.0.2</version> <configuration><source>1.6</source><target>1.6</target> </configuration></plugin> 5/5/11 25 Chris Roeder, Kevin Livingston
  • 26. Mojo:Maven CommandsGoals Maven is implemented in a number of plugins. Each plugin has one or more goals (commands) giving your install some kind of “mojo” Goals are executed by naming them and their plugin: <plugin>:<goal> mvnarchetype:generate Maven groups goals can be associated with “lifecycle phases”, and run simply by naming a phase mvninstall 5/5/11 26 Chris Roeder, Kevin Livingston
  • 27. Maven Phases A phase can have zero or more goals associated with it. A lifecycle is a series of phases leading up to a package type. Phases are ordered, and require successful completion of prior phases. The default lifecycle is for jars, and consists of phases that run the following goals: 5/5/11 Chris Roeder, Kevin Livingston 27
  • 28. Runtime Tool A plugin, exec, allows you to call java from Maven so you can use the classpath assembly features to run. Consider what possibilities this creates: Deliver a running project with just one file: the pom. 5/5/11 28 Chris Roeder, Kevin Livingston
  • 29. Runtime 2: The getResourceAsStream Soap Box Not all projects remain naïve of the file system. Some expect to be able to open files using either absolute or relative filepaths and the File class. These files can’t be buried in a jar file. Use maven-assembly-pack to build a deployment assemply. Unpack with maven-dependency-unpack. 5/5/11 Chris Roeder, Kevin Livingston 29
  • 30. Review: Maven Vocabulary Project Pom – a file that tells maven about a particular project. Artifact – a jar, war, pom or other thing required by a project Dependency – something your project needs from another project. Coordinates – the comination of attributes that identify an artifact Repository – a place for artifacts. Lifecycle – a series of steps to produce an artifact. Phase – one of the steps in a Lifecycle. Plugin (Mojo) – added capability Install – putting an artifact into your local ~/.m2/repository Deploy – putting an artifact into a repository Reactor – a process that analyzes and resolves dependencies and runs the build. It is the innermost (if temporary) container of artifacts. 5/5/11 Chris Roeder, Kevin Livingston 30
  • 31. Review: Standard Directory Layout (with UIMA additions) http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html src main Java edu.isi.bmkeg… Resources desc/ae desc/cpe desc/cr typeSystem models test java resources target Product-0.1-SNAPSHOT.jar (created by build run) 5/5/11 Chris Roeder, Kevin Livingston 31
  • 32. Advanced Topics(not covered here) Archetypes are a way of building a template for maven templates (poms). Maven does a lot in terms of Dependency Management: What if you have 2 jars that each depend on a third jar, but different versions? Maven picks the most recent, but this assumes backward compatibility. Scope: items within maven can be scoped to a phase, so for example, jUnit doesn’t have to ship with the production jar. SCM integration: How does this integrate with Subversion? Eclipse Integration: m2 eclipse plugin Site Utilities: a project info web site can be built that includes author and test info. among others. 5/5/11 Chris Roeder, Kevin Livingston 32
  • 33. Caution The learning curve can be steep. Be patient: you’ll write less SCM code. Follow Convention. Don’t be afraid to violate Convention. Get a second opinion. Read the errors bottom-up. Run “mvn clean” and “rm ~/.m2/repository” when things get real weird. http://www.sonatype.com/books/mvnex-book/reference/public-book.html 5/5/11 33 Chris Roeder, Kevin Livingston
  • 34. Thank You Hunter Lab Software Engineers for keeping the bar high: Bill Baumgartner Yuriy Malenkiy ISI’s SciKnowMine project for using tools that practically require Maven: Cartic Ramakrishnan Gully Burns 5/5/11 34 Chris Roeder, Kevin Livingston