Maven common commands and Eclipse apps

Source: Internet
Author: User

In general, most Java projects on GitHub are built using maven,ant and so on. Because Maven has not been used before, this is a simple study of maven these days. The saying goes: "Warm so know the new", some commands are not used for a long time will be forgotten, so want to use this blog to record their results of Maven learning, wait until the use of the review. Maven is described first, followed by Maven's installation configuration and integration with Eclipse, and finally the MAVEN common commands, MAVEN's general project structure, and Maven's pom files.

I. Introduction to MAVEN

MAVEN is a powerful project building and management tool, developed in Java, under the Apache Open Source project, now the latest version of the Apache Maven 3.3.9, the official website for http://maven.apache.org. MAVEN is cross-platform and powerful, enabling users to complete a range of operational processes from cleanup, compilation, testing, reporting, packaging, and deployment. Maven standardizes the process of building a project and facilitates collaboration between teams. In addition, MAVEN can effectively solve the problem of dependency of jar packages in Java projects, and solve the problems caused by the inconsistency of versions. MAVEN also provides a free central repository that can be found in almost any open source class library.

Two. MAVEN Installation and configuration

(1) Installation configuration local maven

Before installing MAVEN, you must ensure that your computer has installed and configured the JDK environment, and then download the MAVEN version http://maven.apache.org/download.cgi that you want to install from the official website, where I install Maven 3.3.9. Then configure the environment variables according to your installation path, specifically create a new system variable maven_home, and set the MAVEN path for installation, such as:

Finally, in the system variable path plus;%maven_home%\bin. After that, enter mvn-version on the command line to determine if the installation was successful, and if the following interface appears to prove the installation was successful.

You can start using MAVEN when the above steps are complete, but Maven places the repository under/m2/repository in the user's Temp folder by default, but for ease of administration you can do so by setting the Setting.xml file under the Conf folder < The localrepository></localrepository> node customizes the local warehouse content. I re-set the local warehouse folder E:/m2/repository with the E-disk and set up the Setting.xml file: <localrepository>e:/m2/repository</localrepository >.

In this way, we have completed MAVEN's installation configuration and customized the location of the local repository, entered MVN help:system on the command line and can see that local maven has downloaded some files from the central repository to the local repository.

(2) configuring Maven in Eclipse

Eclipse is a familiar IDE that allows MAVEN to be installed and configured directly by downloading the M2eclipse plugin, which does not facilitate the management and use of MAVEN. I recommend that you use local maven to configure it in Eclipse. After all the actions in the specific completion (1) determine that the MAVEN installation is configured correctly, first add Maven to the eclipse->window->preferences->maven->installations, such as:

And then in Eclipse->window->preferences->maven->user Settings set the local warehouse and corresponding Setting.xml file location, as follows (I copied a copy of the Setting.xml file to the local Repository M2 folder, to indicate that this is the settings for the warehouse, or directly use the Setting.xml file under the Maven installation file):

This completes the Eclipse configuration locally installed MAVEN environment, and if the MAVEN plugin option is not present in Eclipse Window->preferences, you can refer to the blog http://blog.csdn.net/truong/ article/details/37834053 to solve the problem.

Three. Maven Common commands

This section describes several common MAVEN commands that you can view when you forget.

Mvn-version view maven's version and configuration information

MVN archetype:create-dgroupid= dartifactid= Building a Java project

MVN archetype:create-dgroupid= dartifactid=-darchetypeartifactid=maven-archetype-webapp Creating a Web project

MVN Compile compiling Project code

MVN Package Project

MVN package-dmaven.test.skip=true to skip unit tests when packaging a project

MVN Test Run Unit tests

MVN clean clears the contents of the target folder generated by the compilation and can be used in conjunction with the corresponding command, such as the MVN. MVN Clean Test

MVN install it in the local warehouse after it is packaged

MVN deploy to a remote repository configured in the Pom file after it is packaged

MVN Eclipse:eclipse Build the Eclipse project structure with maven

MVN Eclipse:clean Clear Project structure for Eclipse in MAVEN project

MVN Site Generation Directory

MVN dependency:list shows all dependencies that have been resolved

MVN Dependency:tree The structure of the tree to show dependencies in the project

MVN dependency:analyze Analysis of dependencies in a project, dependency not used, use single not introduced

MVN Tomcat:run Start Tomcat

1. Common commands

MVN archetype:generate--Build Project  MVN clean--Project cleanup  mvn test--Project Unit Test compilation MVN  compile--Project source code compilation  MVN package--Project Package  MVN install--release project submitted to local warehouse  MVN deploy--Publish project to  MVN jetty:run--launch jetty container    mvn eclipse: clean--clear some system settings for Eclipse                 mvn eclipse:eclipse--generate Eclipse project files mvn idea:clean--Clear some system settings for idea                 mvn idea: idea--generate the Idea project file Mvn dependency:tree--view dependency tree  mvn assembly:assembly--need to be equipped with assembly plug-in, can be used to package the specified file Tar.gz,zip Package// Specify maven parameter:  -dskiptests=true--default unit test not going  

Tip 1: For MAVEN parameters, the uppercase d in front of the parameter is the symbol that passes the parameter, followed by the real name of the parameter, this argument can refer to "Maven combat" a book, there is a detailed explanation. Links: https://item.jd.com/10476794.html

Tip 2: Personal understanding, MAVEN is actually a combination of plug-in mechanism, such as Archetype,eclipse,jetty,idea these, each represents a plug-in. For example, why archetype use grenrate, and parameters to pass the generation, direct search: Maven archetype plugin.

When prompted 3:maven executes, there are sequential, such as MVN clean test compile, if you run MVN compile separately, the clean,test command is executed by default.

2, commonly used to build project Skeleton command

Build Application project: MVN archetype:generate-darchetypecatalog=internal-darchetypeartifactid= Maven-archetype-quickstart  Build Web project: MVN archetype:generate-darchetypecatalog=internal-darchetypeartifactid= Maven-archetype-webapp  

Tip 1: As explained above, archetype is essentially a plugin, then we can directly search the usage of this plugin, official link: http://maven.apache.org/guides/introduction/ Introduction-to-archetypes.html, on the right side of the page, if you have hyperlinks, you can click to see other extension instructions.

Tip 2: And for Maven-archetype-quickstart These parameters, is also available on the official website, reference: http://maven.apache.org/archetypes/index.html, which explicitly gives the example and the meaning of creating folders represents what.

When the above command executes, you are prompted to enter Groupid,artifactid this information, and then enter it to complete.

For example, if we want to generate a project skeleton by default, it can be the following command:

MVN archetype:generate-darchetypecatalog=internal-dgroupid= (project group) com.jsoft.testproject-dartifactid= (project name/module name) Testmaven-dversion= (version number) 1.0-snapshot  -dpackage= (package name) Testpackage

Tip 1: The above creation is a Maven-archetype-quickstart-based project.

Tip 2: Similarly, after testing, whether it is a new QuickStart project or a WebApp project, as long as the folder is new.

3. Folder description for MAVEN project

A standard MAVEN project with QuickStart as the main folder directory structure is as follows:

The directory structure of the WebApp project is as follows:

Note: The WebApp project will have an extra WebApp folder on the main folder, and the WebApp folder will not appear on the test folder, which means that the unit test is the test logic code.

And if you use the MAVEN command to create a new WebApp project, the default is not with the test folder, the test folder can be created later, for why not new, in fact, the official default does not. Reference:

MAVEN's official Most standard directory layout: http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html

4. The application of Maven in eclipse

In the latest version of Eclipse, the plugins that have been integrated with MAVEN by default can be easily integrated with various commands. The eclipse is as follows:

For example, to execute a mvn compile command, the action is: Maven build ..., note: Here Maven build is to execute the last command, so do not mistake; then enter compile

Appears as above built, proves to have succeeded.

For WebApp projects, you can test with run as server, and if your project doesn't work, it's definitely not a successful configuration.

Most of the time we have not tested with Tomcat, and instead use faster and lighter jetty, such as MVN Jetty:run.

Maven common commands and Eclipse apps

Related Article

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.