MAVEN Create Project

Source: Internet
Author: User

------------------------------Maven3 Common commands--------- ------------------

1. Common commands

1) Create a project

MVN archetype:generate-dgroupid=com.mycompany.app-dartifactid=my-app-darchetypeartifactid= Maven-archetype-quickstart-dinteractivemode=false

MVN archetype:generate Fixed format

-dgroupid Organization identification (package name)

-dartifactid Project Name

-darchetypeartifactid specify Archetypeid,maven-archetype-quickstart, create a Java Project;maven-archetype-webapp, create a Web Project

-dinteractivemode whether to use interactive mode

2) compiling the source code

MVN Compile

3) Compile the test code

MVN Test-compile

4) Clear

MVN clean

5) Run the test

MVN test

6) Production Site Directory and packaging

MVN Site-deploy

7) Install the current project's output file to the local repository

MVN Install

8) Packaging

MVN Package

9) First clear and then pack

MVN Clean Package

10) hit into a jar package

MVN Jar:jar

11) Build Eclipse Project

MVN Eclipse:eclipse

12) View Help information

MVN help:help

13) See what Project type categories maven has

MVN archetype:generate-darchetypecatalog=intrenal

 2. The standard MAVEN project structure

                    

Src/main/java storing the source code of the project

Src/test/java Store Test Source code

If you want to store some configuration files, you can set up a directory Src/main/resource storage, such as storage log4j.properties, etc.

Build---------------------------------------------------------Java Project

Build a simple Java project with Maven

 1. Go to the command line and execute the following statement.

MVN Archetype:generate-dgroupid=cn.luxh.app-dartifactid=my-app-darchetypeartifactid=maven-archetype-quickstart- Dinteractivemode=false

When execution is complete, you can see the following results:

Build SUCCESS, when a Java project is built under the previous user directory (that is, C:\Documents and Settings\Administrator) is called My-app.

  2, enter the My-app directory, you can see there is a pom.xml file, this file is the core of Maven.

1) Pom means Project object model.

2) pom.xml contains information on project construction, including project information, project dependencies, etc.

3) pom.xml files can be inherited, in large projects, the pom.xml of the submodule will generally inherit from the parent module Pom.xml

4) Pom.xml Description of the newly constructed

<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/maven-v4_0_0.xsd" >  < modelversion>4.0.0</modelversion>  <groupId>cn.luxh.app</groupId>  <artifactid >my-app</artifactId>  <packaging>jar</packaging>  <version>1.0-snapshot</ version>  <name>my-app</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>

Node Element Description:

       The top node <modelVersion> object model version of the <project> Pom file can only be 4.0.0 for Maven2 and Maven3 <groupId> A project creates an identifier for an organization, typically a domain name that is inverted <artifactId> defines the unique identity of the project under the identifier of the owning organization, under which an organization can have multiple projects <packaging>  packaging, with Jars, W     AR, ear, etc. <version>  current project version, SNAPSHOT, represents the snapshot version, in development <name> project name <url> Project address <dependencies> description of the Jar <description> Project on which the project was built

Where the GroupID, Artifactid, and version uniquely determine a project's coordinates

 3, the construction of the MY-APP project structure is as follows

                    

1) Compile the source program, go to the command line, switch to the My-app directory, execute the command: MVN clean compile

Compile successfully, in the My-app directory, a more target directory, target\classes inside is the compiled class file.

2) test, go to command line, switch to My-app directory, execute command: MVC clean test

The test succeeds, there will be a test-classes directory under the My-app\target directory, which is the class file of the test code.

3) package, go to the command line, switch to the My-app directory, execute the command: MVC clean packages, execute the compile and test commands before executing the package command

After the build succeeds, the My-app-1.0-snapshot.jar package is generated in the target directory.

4) Install, go to the command line, switch to the My-app directory, execute the command: MVC clean Install, perform the compile, test, and package commands before executing the installation command

If the build succeeds, the project's jar package is installed to the local repository.

5) Run the jar package, go to the command line, switch to the My-app directory, execute the command: JAVA-CP target\my-app-1.0-snapshot.jar cn.luxh.app.App

------------------------------Web project Build---------------------------

1. Enter the command line and execute:

MVN Archetype:generate-dgroupid=cn.luxh.app-dartifactid=my-web-app-darchetypeartifactid=maven-archetype-webapp- Dinteractivmode=false

There are some version number confirmation, such as direct return to the line, the following prompt build success.

Under the current user directory, the resulting Web project directory structure is as follows:

                        

2, of course, this empty project, only a index.jsp page, packaging release run.

1) switch to the My-web-app directory at the command line, execute: MVN package, after the build is successful, the My-web-app directory has more than one target directory, This directory will be packaged as a My-web-app.war, and the war package can be copied to the Tomcat release directory to run.

2) Integrated jetty release run, need to configure Pom.xml.

<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/maven-v4_0_0.xsd" > <modelversion >4.0.0</modelVersion> <groupId>cn.luxh.app</groupId> <artifactid>my-web-app</ artifactid> <packaging>war</packaging><!--Web Project Default packaging method War--> <version>1.0-SNAPSHOT< /version> <name>my-web-app Maven webapp</name> <url>http://maven.apache.org</url> < dependencies> <dependency> <groupId>junit</groupId> <artifactid>junit</artifact id> <version>3.8.1</version> <scope>test</scope> </dependency> </depende ncies> <build> <finalName>my-web-app</finalName> <pluginManagement> <!--configuration Jett y--> <plugins> <plugin> <groupId>org.mortbay.jetty</groupid> <artifactId>maven-jetty-plugin</artifactId> </plu gin> </plugins></pluginManagement> </build> </project>

Then execute: MVN jetty:run can access the application on port 8080.

MAVEN Create 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.