Maven.apache Download and Installation _maven

Source: Internet
Author: User
Tags apache download object model jboss

Maven is an open source project management tool that is written in pure java. MAVEN uses a concept called the Project object Model (POM) to manage projects, and all project configuration information is defined in a file called Pom.xml, through which Maven can manage the entire declaration cycle of the project, including compiling, building, testing , publishing, reporting, and so on. Most of the projects currently under Apache have been managed using MAVEN. MAVEN itself also supports a variety of plug-ins to facilitate more flexible control of the project.
1: Download the latest version of Maven 3.0.2 (Binary Zip)

2: Extract to D:

3: Configure Environment variables
maven_home:d:\apache-maven-3.0.2
MAVEN:%maven_home%\bin
(optional) Maven_opts:-xms256m-xmx512m
Add%maven% in front of path;

4: Verify that the installation is successful
On the command line, enter: mvn-version; Carriage return, if you see the following information indicating successful installation:

5: Create the project
Enter on the command line: mvn archetype:create-dgroupid=com.mycompany.app-dartifactid=my-app carriage return,

If you are running the command for the first time (goal), MAVEN will take some time to download the latest toolkit (maven called it artifacts) to your local repository.

After the command is done, you will see that MAVEN has generated a directory named My-app, which is the artifactid you specified in the command, and you will find the following standard project structure:

Where: The Src/main/java directory contains the source code for the project, the Src/test/java directory contains the project's test code, and Pom.xml is the Project object model (Project objects or POM).
6:pom
The Pom.xml file is the core configuration of Maven for a project that will contain most of the configuration information you want to build your project. Pom is big and complex, but you don't have to understand it all, just use some of the usual configurations. The contents of this pom are listed below:

Reference

<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>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>my-app</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

7: The 5th step what did we do

Reference

MVN Archetype:create-dgroupid=com.mycompany.app-dartifactid=my-app

Execute MAVEN Command (goal) Archetype:create, and set some parameters (-dgroupid=com.mycompany.app-dartifactid=my-app)
In this command, the prefix archetype is the plugin of a maven containing the create command. The goal command builds a simple project based on the project prototype, which conforms to the MAVEN standard project template.
It is now certain that a MAVEN plugin is a collection of goals commands with the same purpose, such as the Jboss-maven-plugin plug-in, to handle various JBoss-related tasks.
8:build Project
Enter on the command line: CD My-app carriage return, go to the project path

Then enter MVN package carriage return the command line will print out various actions and end with the following message:

With the first execution of the command (that is a goal)

Reference

Archetype:create

Different, this time the execution is just a simple command---package. Unlike goal, this is a phase (phase), a phase refers to the construction of a life cycle phase, the construction of life cycle is an ordered series of phase. When given a phase,maven will perform all the phase and itself before this phase, for example, if we perform the compile phase, the actual stage of execution is:

Reference

Validate
Generate-sources
Process-sources
Generate-resources
Process-resources
Compile

You can use the following command to test the newly compiled and packaged jar packages.

Reference

JAVA-CP Target/my-app-1.0-snapshot.jar com.mycompany.app.App

This will print out the most classic:

Reference

Hello world!


9: Run the Maven tool
Although it is difficult to list a very comprehensive table, here you can first list the most common default lifecycle stages:

Reference

Validate: Verify that the project is correct and that all required resources are available.
Compile: Compiles the source code for the project.
Test: Tests the compiled source code with the appropriate unit test framework. These tests do not need to be packaged and installed.
Package: Package The compiled code into a published format, such as a jar.
Integration-test: If necessary, process and publish packages to an environment where integration testing can take place.
Verify: Run all checks to verify that the package is valid and meets quality standards.
Install: The package is installed in the local repository and can be used by other engineering as a dependency.
Deploy: Execute in an integrated or publishing environment, copy the final version of the package to a remote repository, so that other developers or projects can be shared.
Clean: Clears the previously built artifacts (in Maven, the project-generated packages are called artifact).
Site: Generates a document site for the project.

The individual phases (phases) listed above actually correspond to the potential goals, and special goals performed by each phase of the project are determined by the type of the item, for example, if the type of the project is Jar,package and the Jar:jar is executed by default, If the project type is war, then the goals executed in the package phase will be war:war. &NBSP
One interesting thing to note is that phases and goals need to be executed in a certain order.  
mvn clean dependency:copy-dependencies package 
This command clears the project, then copies dependencies, and finally packs the items, of course, before packing, The stage before this stage is performed. such as Compile,test. &NBSP
Build site  
mvn site 
This phase generates project information based on Pom.xml configuration. You can see the resulting document in the Target/site directory.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.