Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Aphorismen
Applications
Business Economics & Admin.
My Computers
Cooking
Devices
Folders
Food
Hardware
Infos
Software Development
Sports
Operation Instructions
Todos
Test
Help
Glossary
Community portal
adaptions
Sidebar anpassen
Wiki RB4
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Maven
Page
Discussion
English
Read
Edit
View history
Toolbox
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==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 is written in Java and is used to build projects written primariyl in Java, but also for C#, Scala, Ruby, etc. Based on the Project Object Model (POM), this tool has made the lives of Java developers easier while developing reports, checks build and testing automation setups. It defines a [https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html standard directory layout]. ===Lifecycles=== Maven beinhaltet als wichtiges Konzept genau definierte Build '''Lifecycles'''. Die drei eingebauten Standard-Lifecycle sind: * '''clean''' * '''default''', handles project build and deployment * '''site''', handles creation of documentation ===Phases=== Build Lifecycles bestehen aus Lifecycle bzw. Build-'''Phasen''', die sequentiell ausgeführt werden. mvn <PHASE> Beim Aufruf einer Phase werden vor der Phase auch die Vorgänger ausgeführt. The most common phases are (full list see [http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference here]): *clean *validate *compile *test *package: take the compiled code and package it in its distributable format, such as a JAR *integration-test *verify *install: install the package into local repository e.g. for use by different projects locally *site: generate documentation to /target/site *deploy: copy package to remote repository for sharing with other developers The '''default lifecycle''' is made up of the following phases: * validate * compile * test * package * verify * install * deploy ===Goals=== A build phase is made up of a set of '''goals'''. Goals sind somit kleinere Tasks und vergleichbar mit Ant-Tasks. Goals können auch mehreren Phasen zugeordnet werden, oder sogar keiner Phase. Einige Phasen haben Standard Goals. Goals können direkt mit der Syntax '''mvn''' <PLUGIN>''':'''<GOAL> aufgerufen. To list all goals of a phase by mvn help:describe -Dcmd=<PHASE> // e.g. mvn help:describe -Dcmd=compile To list all goals in order how they are executed mvn fr.jcgay.maven.plugins:buildplan-maven-plugin:list ===Plugins=== Maven-'''Plugins''' sind Bibliotheken, die thematisch zusammengehörende Goals implementieren bzw. Gruppen von Goals beinhalten. Wichtige Plugins sind zum Beispiel: *archetype *compiler *surefire *jar *war *install *deploy *site *dependency *eclipse *jetty. To list all goals of a plug-in mvn <PLUGIN>:help // e.g. mvn spring-boot:help or mvn exec:help ===Archetype=== Ein '''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. Archetypes haben ===Artefakt=== '''Artefakt''' sind im Zusammenhang mit Maven Arbeitsergebnisse gemeint. Maven-Projekte haben in der Regel ein Hauptergebnis-Artefakt, oft eine jar-, war- oder ear-Datei. Artefakte werden in Repositories abgelegt. Mit '''Koordinaten''' werden die fünf ein Artefakt identifizierenden Informationsbestandteile bezeichnet. Oft sind vor allem die drei wichtigsten gemeint: * groupId (usually a reversed domain name), * artifactId (name of the root directory) * version (string). Maven uses the groupId, artifactId, and version to identify dependencies (usually other jar files) needed to build and run your code. Commonly a software project build with maven consists of many maven-projects that build artifacts (e.g. jars) that constitute the product. Each maven project has a unique identifier consiting of [groupId, artifactId, version]. When a maven project requires resources of another project a dependency is configured in it's pom.xml using the above-mentioned identifier. The artifacts of the required projects are then loaded either from the local repository, which is a simple directory in your user's home, or from other (remote) repositories specified in you pom.xml. In Java programmierte eigene Maven-Plugins bestehen aus '''Mojos'''. Ein Mojo ("Maven (plain) old Java Object") ist eine Java-Klasse die das Interface org.apache.maven.plugin.Mojo implementiert (oder org.apache.maven.plugin.AbstractMojo erweitert) und damit ein Plugin-Goal realisiert. ===Profiles=== '''Profiles''' let you customize the build for different environments. Often you have property files that specify database connections and passwords for your development, staging, and production environment. Profiles can obviously be defined on different levels and can contain different specifications e.g. <profiles> <profile> <id>local_dev</id> <activation> <activeByDefault>true</activeByDefault> </activation> <dependencies> <dependency> ... Profiles are activated by the -P parameter e.g. <code>mvn clean install -Plocal_dev</code>. ==Repository== There are central and a local repository. The local repository is used for: * downloaded jars referenced in the projects * downloaded jars maven needs The '''central repositories''' ([http://mvnrepository.com/ mvnrepository]) are used: * to store plugins The '''local repository''' on Windows computers is in C:\Users\U1728\.m2\repository ==Installation== * see [[EDTLaptop1#Maven|Windows Laptop]] ==Conventions== * [http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html Standard Directory Layout] ==Project Configuration== All information is stored in pom.xml (Project Object Model). ===pom.xml=== Pom.mxl is an XML file that contains information about the project and configuration details used by Maven to build the project. It contains default values for most projects. Examples for this is the build directory, which is <code>/target</code>; the source directory, which is <code>src/main/java</code>; the test source directory, which is <code>src/main/test</code>; and so on. When executing a task or goal, Maven looks for the POM in the current directory. It reads the POM, gets the needed configuration information, then executes the goal. The Super POM is Maven's default POM. All POMs extend the Super POM unless explicitly set, meaning the configuration specified in the Super POM is inherited by the POMs you created for your projects. ====<project>==== <project> <modelVersion> </modelVersion> <!-- mandatory e.g. 4.0.0 --> <groupId> </groupId> <!-- mandatory, organization identifier e.g. www.uweheuer.de --> <artefactId> </artefactId> <!-- mandotory, base name of the primary artefact extended with version and extension, name of the root directory --> <packaging> </packaging> <!-- package type with impact on the lifecycle --> <version> </version> <!-- mandotory --> <!-- groupId, artifactId, and version form the project's fully qualified artifact name --> <name> </name> <!-- for documentation --> <url> </url> <!-- for documentation --> <description> </description> <!-- for documentation --> [[Maven#.3Cdependencies.3E|<dependencies>...</dependencies>]] [[#.3Cbuild.3E|<build>...</build>]] </project> ====<dependencies>==== <dependencies> ... </dependencies> ====<build>==== <build> ... <plugins> [[#.3Cplugin.3E|<plugin>...</plugin>]] </plugins> </build> ====<plugin>==== =====JBoss AS Plugin===== <plugin> <groupId>org.jboss.as.plugins</groupId> <artifactId>jboss-as-maven-plugin</artifactId> <version>7.1.0.Beta1b</version> </plugin> mvn [jboss-as:deploy|jboss-as:redeploy|jboss-as:undeploy] ==Operation== mvn -version mvn [<phase>|<plugin>''':'''<goal>] mvn clean mvn compile mvn test // delete all artefacts and target dir mvn package // build artefacts mvn help:active-profiles ===Creating a project=== mvn archetype:generate // starts a wizard beginning with selecting an archetype mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.mycompany.app -DartifactId=my-app archetypeArtifactId // template archetypeGroupId // template archetypeVersion // template artifactId // => new project folder and eclipse project name groupId // => new project package structure ===Using Maven in Eclipse=== * see [[Eclipse#Maven|here]] ===Using JBoss Plugin=== http://www.mastertheboss.com/jboss-maven/maven-jboss-as-7-plugin-tutorial/page-2 mvn jboss-as:deploy ==Resources== * [http://maven.apache.org/index.html Maven Homepage] * http://www.torsten-horn.de/techdocs/maven.htm * [http://books.sonatype.com/mvnref-book/reference/index.html The complete Reference] * C:\Uwes\Documents\Manuals\maven_tutorial.pdf
Summary:
Please note that all contributions to Wiki RB4 may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Uwe Heuer Wiki New:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width