MAVEN installation and simple use tutorial

Source: Internet
Author: User

MAVEN is a Java Project management tool in which all project configuration information is defined in a text called Pom.xml that covers the entire lifecycle of the project, including Project creation, compilation, testing, and publishing.

First, the preface
When you use Eclipse, you will find that you can import the MAVEN project directly,

Because the IDE defaults to the Maven plugin (I'm under the Java version)

But for a management tool, the use of the IDE is just easy to develop, and the command line is needed from a management standpoint.

Ii. installation of Maven
Maven command line installation method, very simple Baidu can search

Third, maven create command

1. Create command: Maven 3.0.5 version used the MVN archetype:generate,3.0.5 version before using MVN archetype:generate

Executes the Create Project command under a directory.

To create a Java project:

mvn archetype:generate -DgroupId=com.my.java.app -DartifactId=my-javaapp -DarchetypeArtifactId=maven-archetype-quickstart

To create a Web project:

mvn archetype:generate -DgroupId=com.my.web.app -DartifactId=my-webapp -DarchetypeArtifactId=maven-archetype-webapp


Parameters:
GroupId: Total project name
Artifactid: Sub Project name
Archetypeartifactid: Use the template for the project, each template will create a corresponding directory structure and some common files

Under the project directory:
MVN compile: Compiling source code
MVN Clean: Clear compilation file (target directory was killed)
MVN test-compile: Compiling test code
MVN test: Run Tests in Directory
MVN package: Compiles, tests, packs, and the current project's jar pack is placed under the target directory
MVN install: Compiles, tests, packs, and stores the jar package for the current project into the local repository

Iv. the concept of the warehouse
In Maven, there are two warehouses of local and central libraries. The central repository defaults to the common library provided by the Apache site, where the local repository downloads the jar packages that need to be relied on locally.
The local library can be configured in the Conf/settings.xml under the MAVEN installation directory.
You can use Nexus to build a central library in your company. Through the intranet to access the company project depends on the jar package.

V. Directory structure
D:. ├─my-javaapp│  │  pom.xml│  ││  ├─src│  │  ├─main│  │  │  └─java│  │  │      └─com│ │ │          └─my│  │  │              └─java│  │  │                  └─app│  │                          │ app.java│  │  ││  │  └─test│  │      └─java│  │          └─com│  │              └─my│  │                  └─java│  │                      └─app│  │                              apptest.java│  ││  └─target

Pom.xml:Maven Core Files
Src/main/java: Source code path
Src/test/java: Test code path
Target: Compiled class file or package file path
Src/main/resources: (optional) configuration file path

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.