MAVEN installs and builds simple projects

Source: Internet
Author: User

Main functions of 1.maven

The ability to manage a project-dependent jar package allows the project to maintain basic dependencies, eliminate redundant jar packages, and make it very easy to version-upgrade a dependent jar package. These are just the basic features of MAVEN, which can be used to build projects such as cleaning, compiling, testing, packaging, publishing, and so on.

2.maven Download and Installation

(1) Download

Download the latest version from http://maven.apache.org/.

(2) Decompression

Unzip the downloaded zip file to the local directory and I placed it under the C:\Program files\apache-maven-3.3.1-bin directory.

(3) Configuring the Environment

Computer-System Properties-Advanced system settings-environment variable-path-add C:\Program files\apache-maven-3.3.1-bin\apache-maven-3.3.1\bin

(4) Run under the command line

Start-run, enter CMD carriage return. or press windows+r on your keyboard to enter CMD

At the Windows command prompt, enter mvn–v

3. Build a "HelloWorld" project with Maven

In the console, enter the command:

MVN archetype:generate

-dgroupid=com.helloworld.app

-dartifactid=helloworld

-dversion=1.0

-darchetypeartifactid=maven-archetype-quickstart

After waiting for the load to complete, you can see the resulting folder in the appropriate directory

It contains a Java source file and a Java test file

Note:

GROUPID defines which group the project belongs to, which is often associated with the organization or company where the project resides.

Artifactid defines the unique ID of the current MAVEN project in the organization, which can be understood as a module in the project, and the module is the smallest unit widget in Maven

Versions of version projects

4. Use "Compile, test, package" to build the project.

Enter CD HelloWorld in cmd and switch directory to HelloWorld

Compiling: Compile

CMD directory HelloWorld execution mvn compile

After waiting for the load to complete, we will see a new target directory under HelloWorld, which holds the project's compiled files, such as the. class file

Testing: Test

CMD directory HelloWorld execute command MVN test

The JUnit test code under Src/test/java will be executed, waiting for the run result to be seen after loading is complete.

Packaging: Package

CMD directory HelloWorld execute command MVN package

The project is made into a jar package and placed in the target directory, and the compile and test commands are executed before executing this command

Cleanup: Clean

CMD directory HelloWorld execute command mvn clean

The target file is deleted, that is, the cleanup project, which can be run with other commands

Installation: Install

CMD directory HelloWorld execute command mvn install

The project jar package is installed in the local warehouse so that other projects can use the

The compile, test, and package commands are executed before executing this command

MAVEN installs and builds simple projects

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.