Maven: Difference between revisions
| Line 33: | Line 33: | ||
<project> | <project> | ||
<modelVersion> </modelVersion> | <modelVersion> </modelVersion> | ||
<groupId> </groupId> | <groupId> </groupId> <!-- organization identifier e.g. www.uweheuer.de --> | ||
<artefactId> </artefactId> <!-- base name of the primary artefact extended with version and extension --> | <artefactId> </artefactId> <!-- base name of the primary artefact extended with version and extension --> | ||
<packaging> </packaging> <!-- package type with impact on the lifecycle --> | <packaging> </packaging> <!-- package type with impact on the lifecycle --> | ||
Revision as of 22:59, 7 January 2012
Introduction
Maven is an attempt to apply patterns to a project's build infrastructure in order to promote comprehension and productivity by providing a clear path in the use of best practices. Maven is essentially a project management and comprehension tool and as such provides a way to help with managing:
- Builds
- Documentation
- Reporting
- Dependencies
- SCMs
- Releases
- Distribution
Maven beinhaltet als wichtiges Konzept genau definierte Build Lifecycles. Die drei Standard-Lifecycle sind: clean, default und site. Build Lifecycles bestehen aus Lifecycle-Phasen. Wichtige Phasen sind beispielsweise: clean, compile, test, package, integration-test, verify, install, deploy und site. In den Lifecycle-Phasen werden jeweils bestimmte Plugin-Goals ausgeführt. Maven-Plugins sind Bibliotheken, die thematisch zusammengehörende Goals implementieren. Wichtige Plugins sind zum Beispiel: archetype, compiler, surefire, jar, war, install, deploy, site, dependency, eclipse und jetty. Goals können bestimmten Lifecycle-Phasen zugeordnet werden und werden dann automatisch zum richtigen Zeitpunkt aufgerufen (z.B. "compiler:compile"). Maven-Goals sind vergleichbar mit Ant-Tasks.
Ein Maven-Archetype ist ein Projekt-Template. Über das archetype-Plugin können Standard-Directory-Layouts und Projektvorlagen für verschiedene Projekttypen erstellt werden (z.B. quickstart, webapp und mojo). Dabei wird auch eine vorläufige pom.xml angelegt.
Artefakt sind im Zusammenhang mit Maven Arbeitsergebnisse gemeint. Maven-Projekte haben in der Regel ein Hauptergebnis-Artefakt, oft eine jar-, war- oder ear-Datei. Mit Koordinaten werden die fünf ein Artefakt identifizierenden Informationsbestandteile bezeichnet. Oft sind vor allem die drei wichtigsten gemeint: groupId, artifactId und version.
Installation
- by description in http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
- Download from http://maven.apache.org/download.html
- extracted to C:\Uwes\apache-maven-3.0.1
- add environment M2_HOME with C:\Uwes\apache-maven-3.0.1 and M2 with %M2_HOME%\bin
- add %M2% to PATH variable
- test by cmd mvn --version
Configuration
All information is stored in pom.xml (Project Object Model).
pom.xml
<project> <modelVersion> </modelVersion> <groupId> </groupId> <!-- organization identifier e.g. www.uweheuer.de --> <artefactId> </artefactId> <packaging> </packaging> <version> </version> <name> </name> <url> </url> <description> </description> </project>
Operation
mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.mycompany.app -DartifactId=my-app
mvn <cmd> -Dverbose mvn clean mvn compile mvn test // delete all artefacts and target dir mvn package // build artefacts