Common maven2 commands

Source: Internet
Author: User

Reproduced in: http://bakcom.iteye.com/blog/280604

 

 

The running command of maven2 is MVN,

Common commands:

MVN archetype: Create a Maven Project

MVN compile: Compile source code

MVN test-compile: Compile the test code

MVN test: run the unit test in the application.

MVN site: the website that generates project-related information

MVN clean: clears the generated results in the target directory.

MVN package: generate a jar file based on the project

MVN install: Install jar in local repository

MVN Eclipse: generate an Eclipse project file

Generate a project

Create a Java project: MVN archetype: Create-dgroupid = com. Demo-dartifactid = app

Create a WEB Project: MVN archetype: Create-dgroupid = com. Demo-dartifactid = web-app-darchetypeartifactid = Maven-Archetype-webapp

Generate an Eclipse project

Normal Eclipse project execution: MVN Eclipse: Eclipse

Eclipse WTP project execution: MVN Eclipse: eclipse-dwtpversion = 1.0

(Wtp1.0 and later versions can be used)

 

 

Introduction to Basic Nodes of POM. xml files

<Project>: Root Node of the file.
<Modelversion>: The object model version used by POM. xml.
<Groupid>: The unique ID of the organization or group that creates the project.
<Artifactid>: The unique ID of a project, which can be considered as the project name.
<Packaging>: The extension of the package, such as jar, war, and ear.
<Version>: Version number of the product.
<Name>: Project display name. It is often used for Maven-generated documents.
<URL>: The site of the Organization, which is commonly used for Maven-generated documents.
<Description>: Project description, which is commonly used in Maven-generated documents.

 

 

In pom 4, <dependency> also introduces <scope>, which mainly manages the deployment of dependencies.

Currently, <scope> can use five values:

Compile: the default value. It is applicable to all stages and will be released along with the project.

Provided: similar to compile, it is expected that JDK, container, or user will provide this dependency. For example, Servlet. jar.

Runtime: used only at runtime, such as the JDBC driver. Applicable to the running and testing stages.

Test: used only for testing. It is used to compile and run test code. Will not be released along with the project.

System: similar to provided, You need to explicitly provide jar containing dependencies. MAVEN will not find it in repository.

Define Your Own structure

Create an archetype project:

MVN archetype: Create \
-Dgroupid = cn. Prof \
-Dartifactid = prof-Archetype \
-Darchetypeartifactid = Maven-Archetype

Main template file: archetype-resources/POM. xml

Modify content

Modify related sources defined in META-INF/Maven/archetype. xml

Install this project: MVN install

Run the following command to create a project in the new directory:

MVN archetype: Create-dgroupid = com. mergere. mvnbook \

-Dartifactid = proficio-example \
-Darchetypegroupid = com. XXX. MVN \
-Darchetypeartifactid = prof-Archetype \
-Darchetypeversion = 1.0-Snapshot

Directory description

Maven2 directory

Directory

Level 2 Directory

Level 3 directory

Level 4 directory

Description

Pom. xml

 

Maven2 project settings file

Src/

 

Source code directory

Main/

 

Project subject directory Root

Java/

 

Source code directory

Resources/

 

Required Resource Directory

Filters/

 

Resource filter file directory

Assemby/

 

Assembly Descriptors

Config/

 

Configuration File root directory

Webapp/

 

Web application directory

WEB-INF/

WEB-INF directory

Test/

 

Project test directory Root

Java/

 

Test code directory

Resources/

 

Resource Directory required for testing

Filters/

 

Test resource filter file directory

Site/

 

Site-related resource directories

Target/

 

Output directory Root

Classes/

 

 

Project subject output directory

Test_classes/

 

Project test output directory

Site/

 

Project Site output directory

 

 



Problems encountered

1. This error is reported when the m2eclipse plug-in is installed.

Eclipse is running in a JRE, but a JDK is required

Some Maven plugins may not work when importing projects or updating source folders.

Solution: view the details in eclipse \ readme \ readme_eclipse.html. In the selecting a workspace section

Create a shortcut and set the target location to D: \ eclipse_jee \ eclipse.exe-vm d: \ Java \ jdk1.5.0 _ 10 \ bin \ javaw

Because the default VM is JDK, JRE, bin, and javaw, it is directly changed to JDK to eliminate errors.

2. Run the command MVN Eclipse: After eclipse-dwtpversion = 1.0, the Java of the imported project facet is still 1.4, and the value set on Eclipse is 5.0.

Solution: add the Plugins instructions in POM. xml.

XML Code
  1. <Plugins>
  2. <Plugin>
  3. <Artifactid>Maven-compiler-plugin</Artifactid>
  4. <Configuration>
  5. <Source>1.5</Source>
  6. <Target>1.5</Target>
  7. </Configuration>
  8. </Plugin>
  9. </Plugins>
View plaincopy to clipboardprint?
  1. <Plugins> <plugin> <artifactid>Maven-compiler-plugin</Artifactid> <configuration> <source>1.5</Source> <target>1.5</Target> </configuration> </plugin> </plugins>
XML Code
  1. <Plugins> <plugin> <artifactid> Maven-compiler-plugin </artifactid> <configuration> <source> 1.5 </source> <target> 1.5 </Target> </Configuration> </plugin> </plugins>
<Plugins> <plugin> <artifactid> Maven-compiler-plugin </artifactid> <configuration> <source> 1.5 </source> <target> 1.5 </Target> </Configuration> </plugin> </plugins>

 

3. After using the command MVN Eclipse: Eclipse, import it to eclipse. Right-click the Eclipse project and choose plug-in Maven> enable dependency management. An error indicating repeated references will be reported.
Solution: Execute MVN Eclipse: Eclipse, refresh the Eclipse project, and cancel the reference dependency of the maven plug-in. The error will be eliminated.

 

4. Failure executing javac, but cocould not parse the error:
An exception occurs in the compiler (1.5.0 _ 10. If this error is not found in bug parade, archive it in Java Developer Connection (http://java.sun.com/webapps/bugreport. Please include your program and the following diagnostic information in the report. Thank you for your cooperation.
Java. NiO. bufferoverflowexception

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.