Maven Combat (ii) build a simple MAVEN project

Source: Internet
Author: User

1. Create a simple project

Use this command:

MVN archetype:generate-dgroupid=cn.edu.app-dartifactid=simple-dversion=1.0-darchetypeartifactid= Maven-archetype-quickstart

(Here a little explanation, Archetype:generate front archetype said we used the MAVEN archetype plug-in, behind the generate refers to a target of the plug-in, behind Groupid,artifactid, Version these are the basic properties of a project. )

We have entered the above command to create a simple MAVEN project in the current directory, of course, when the creation will be downloaded from the MAVEN library related dependencies, patience to wait.

The approximate structure of MAVEN is as follows:

simple|--pom.xml  '--src      |--main      |   | --java      |   |   '--com      |   |       '--mycompany      |   |           '--app      |   |               '--App.java      |   '--Resources      |       '--Meta-inf      |           '--application.properties      '--Test          '--Java              '--com                  '--mycompany                      '--app                          

Src/main/java : Where Java source files are stored

Src/main/resource : Resource resources, such as configuration files, etc.

src/test/java : Test code source file storage location

2. Simple Pom.xml

Open Project to see Pom.xml

<Projectxmlns= "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/maven-v4_0_0.xsd">  <modelversion>4.0.0</modelversion>  <groupId>Com.mycompany.app</groupId>  <Artifactid>My-app-simple</Artifactid>  <Packaging>Jar</Packaging>  <version>1.0</version>  <name>My-app-simple</name>  <URL>http://maven.apache.org</URL>  <Dependencies>    <Dependency>      <groupId>Junit</groupId>      <Artifactid>Junit</Artifactid>      <version>3.8.1</version>      <Scope>Test</Scope>    </Dependency>  </Dependencies></Project>

The most important part of the segment code is the three lines that contain GroupID, Artifactid, and version. These three elements define the basic coordinates of a project.

groupId defines which group the project belongs to, which is often associated with the organization or company where the project resides. For example, a project called MyApp was built on Googlecode, so groupid should be Com.googlecode.myapp

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

3. Run the simple maven command

We've created the simplest MAVEN project, so let's do some simple build commands

Compiling: Compile

In cmd, switch directory to My-app-simple, execute MVN clean compile

After build success we will see a new target directory under My-app-simple that holds the project's compiled files, such as the. class file

Cleanup: Clean

CMD directory my-app-simple execute command mvn clean

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

Testing: Test

CMD directory my-app-simple execute command MVN test

Will execute the JUnit test code under Src/test/java

Of course, the compilation commands are executed automatically before the test is executed, and the results are as follows:

Packaging: Package

CMD directory my-app-simple execute command MVN package

The item is made into a jar package and placed in the target directory

The compile and test commands are executed before executing this command

Installation: Install

CMD directory my-app-simple 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 Combat (ii) build a simple MAVEN project

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.