Maven for project management

Source: Internet
Author: User

In addition to ant, Maven is the most common project management tool, which is invisible in daily project development. Below is a brief introduction to Maven installation and basic commands.

1.download the maveninstallation file apache-maven-3.2.3-bin.zip. The latest version is 3.2.3. decompress it to the specified directory.


2. Set Environment Variables

M2_home: D: \ Java \ apache-maven-3.2.3-bin \ apache-maven-3.2.3

Path: D: \ Java \ apache-maven-3.2.3-bin \ apache-maven-3.2.3 \ bin or % m2_home % \ bin


3. Enter the command MVN-V in cmd to verify whether the installation is successful.


Now, Maven is successfully installed. You can try again, but there will be more amazing. Since Maven is installed, why not play with it?

5. Create a Maven project and enter the command in the command line to create a project: MVN archetype: Create-dgroupid = com. Test. MAVEN-dartifactid = testmaven

Enter ......


A lot of downloading. Why? Maven will download all dependent packages remotely, so if you do not have a network, you can imagine the result. If no network exists, you should stop MVN. The reason for this is to download all the packages that the project depends on to the local device for use by other modules. At this time, you may ask: where are all downloaded packages stored? Right. Open the bin folder of the maven installation directory and you will see a file.



Open it and check out where the default directory is stored. Check whether many files are added to your directory. Of course, you can modify the default directory to specify the directory you want to store.


After a bunch of balabala downloads, you will start to build the project. If it succeeds, you will see the following content:


You can open the created Project and view the directory structure of the project.

6. introduction to basic MVN commands

Common Maven commands:
1. Create a normal Java project for Maven:
MVN archetype: Create
-Dgroupid = packagename
-Dartifactid = projectname
2. Create a Maven web project:
MVN archetype: Create
-Dgroupid = packagename
-Dartifactid = webappname
-Darchetypeartifactid = Maven-Archetype-webapp
3. Compile the source code: MVN compile
4. Compile the test code: MVN test-compile
5. Run the test: MVN Test
6. Generate site: MVN site
7. Package: MVN package
8. Install jar: MVN install in local repository
9. Clear the generated project: MVN clean
10. Generate Eclipse project: MVN Eclipse: Eclipse
11. Create an idea project: MVN idea: idea
12. Use the goal command in combination. For example, package only and do not test: MVN-Dtest package
13. Compile the test content: MVN test-compile
14. Create a jar package: MVN jar: jar
15. Test without compiling or compiling: MVN test-skipping compile-skipping test-compile
(-The flexible use of skipping can also be used for other combined commands)
16. Clear some system settings of Eclipse: MVN Eclipse: clean

PS:

The general usage is as follows: first download the code to the local machine through CVs or SVN, then execute MVN Eclipse: eclipse to generate the ecllipse project file, and then import it to eclipse; after modifying the code, run the MVN compile or MVN test check. You can also download the eclipse Maven plug-in.

MVN-version/-V displays version information
MVN archetype: Generate create MVN Project
MVN archetype: Create-dgroupid = com. oreilly-dartifactid = My-app create MVN Project

MVN package generates the target directory, compiles and tests the code, generates the test report, and generates the JAR/war file.
MVN jetty: run the project on Jetty,
MVN compile Compilation
Compile and test MVN Test
MVN clean clears the generated file
MVN site: the website that generates project-related information
MVN-dwtpversion = 1.0 Eclipse: Eclipse generates the WTP plug-in WEB Project
MVN-dwtpversion = 1.0 Eclipse: Clean clears the configuration information of the eclipse project (WEB Project)
MVN Eclipse: Eclipse converts a project to an Eclipse project

Use multiple repositories for Applications
<Repositories>
<Repository>
<ID> ibiblio </ID>
<Name> ibiblio </Name>
<URL> http://www.ibiblio.org/maven/ </URL>
</Repository>
<Repository>
<ID> planetmirror </ID>
<Name> planet mirror </Name>
<URL> http://public.planetmirror.com/pub/maven/ </URL>
</Repository>
</Repositories>


MVN deploy: deploy-file-dgroupid = com-dartifactid = client-dversion = 0.1.0-dpackaging = jar-dfile = D: \ client-0.1.0.jar-drepositoryid = Maven-repository-inner-durl = ftp: // xxxxxxx/opt/Maven/Repository/


Release third-party jar files to the local database:

MVN install: Install-file-dgroupid = com-dartifactid = client-dversion = 0.1.0-dpackaging = jar-dfile = D: \ client-0.1.0.jar


-Ddownloadsources = true

-Ddownloadjavadocs = true

MVN-e displays detailed error information.
MVN validate verifies that the project is correct and that all required resources are available.
MVN test-compile: compile the project test code. .
MVN integration-test processes and releases packages in an environment where the integration test can run.
MVN verify runs any check to verify whether the package is valid and meets quality standards.
MVN generate-sources generates any additional source code required by the application, such as XDoclet.



Maven for project management

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.