Got it

Maven usage notes

Latest reply: Dec 11, 2021 11:40:22 1338 15 17 0 0

This post is about the Maven usage notes. Please read below for more details.


Maven lifecycle phase


The Maven provides various life cycle functions for the packaging process, including:


1. Validate: Verify all the contents of the project;


2. compile: Compile;


3. Test: Run test cases;


4. Package: Pack the code and generate it locally;


5. integration-test: Integration tests with other projects will place dependencies in a unified environment.


6. Verify: Check the package quality;


7. Install: Save the packed files to the local repository;


8. Deploy: Save the packed files to the remote repository;


9. clean: Delete the content that has been constructed;


10. Site: Generate a visualized site document for the current project.


Common commands


Each of the preceding life cycles has a corresponding command:


1. mvn compile: Compile code. After compilation, the code is displayed in the /target directory. The IDE automatically executes this step if the IDE is integrated;


2. mvn test: Runs the unit test;


3. For the mvn test-compile, compilation test, use Europe and perform. If you use the IDE in the IDE, you can pack the unit test code.


4. mvn package: Package the project. The package will appear in the /target directory.


5. mvn install: Installation package. The package is installed in the corresponding location of the local repository.


6. mvn deploy to release the package to the remote repository.


The preceding commands are mainly involved in the maven packaging. In addition, the following commands are also available:


mvn site, which is output to a dependency view document of /target.


Elements in the xml file


Project: The top label for the entire XML document


modelVersion: maven model version <modelVersion>4.0.0</modelVersion>


groupId: Organization ID. <groupId>com.mycompany.app</groupId>


artifactId: ID of a symbol. <artifactId>my-app</artifactId>


packaging: Packaging mode, for example, JAR, WAR, EAR. <packaging>jar</packaging>


Version: Current version number. <version>1.0-SNAPSHOT</version>


Name: Project name. <name>Maven Quick Start Archetype</name>


URL: Project address. <url>http://maven.apache.org</url>


Introduction to the description: project.


Test case running rules


Test cases load and exclude files in the format when they are running. The options are as follows:


**/*Test.java

**/Test*.java

**/*TestCase.java

Exclude:

**/Abstract*Test.java

**/Abstract*TestCase.java


Plug-in usage


105637cca8rm2tsmsapp4t.png?image.png


## Resource document management


A Java program must involve various configuration files. In the maven structure, resource files are usually stored in the ${root}/src/main/resources directory. 


For example, application.properties in the following structure:


105711nn0ctcx26vczc80u.png?image.png


Package the JAR file format based on the preceding structure:


105751yimiabnb0bi7nbaa.png?image.png


Resource file parameterization


Generally, some parameters of the production release test and the release test must be different (for example, database link parameters). 


Therefore, the parameters in the resource file need to be changed according to the packing command. The <resources> label (plug-in) is used in this use.


The process of replacing parameters is not complex. The following figure shows the <resources> label.


105921kmmj5zjomiw5icwf.png?image.png


Then, <directory> indicates the path where the parameter is to be replaced. In this example, all the contents in the resource directory are replaced.


Correspondingly, a placeholder is used in the configuration file to indicate the content to be replaced:


Properties:


105957g4rlh4f3lff2rava.png?image.png


yaml:


110017c5o05uy59i95q70y.png?image.png


After the configuration has completed, you can run the mvn process-resources command to check the file replacement effect. After the command has been executed, the replacement effect is displayed in /target/classses.


  • x
  • convention:

user_3427849
Created Jul 27, 2019 09:30:09

very detail,thank you for your share.
View more
  • x
  • convention:

user_4495775
user_4495775 Created Dec 10, 2021 16:21:50 (0) (0)
 
user_3434117
Created Jul 27, 2019 09:36:08

Thanks
View more
  • x
  • convention:

user_4495775
user_4495775 Created Dec 10, 2021 16:21:55 (0) (0)
 
olive.zhao
Admin Created Jul 29, 2019 06:44:40

greatMaven usage notes-3016845-1
View more
  • x
  • convention:

Zebra
Created Apr 17, 2021 10:07:53

Thanks for sharing
View more
  • x
  • convention:

smileymind
smileymind Created Dec 10, 2021 16:22:54 (0) (0)
 
user_4237671
Created Oct 12, 2021 05:27:44

Nice
View more
  • x
  • convention:

Navin_kay
Navin_kay Created Dec 10, 2021 16:25:53 (0) (0)
 
smileymind
Created Dec 10, 2021 16:27:19

Maven usage notes-4482505-1
View more
  • x
  • convention:

azkasaqib
Created Dec 10, 2021 16:44:57

Thanks for sharing
View more
  • x
  • convention:

azkasaqib
Created Dec 10, 2021 16:45:04

Maven usage notes-4483187-1
View more
  • x
  • convention:

AliBinHussain
Created Dec 10, 2021 16:45:58

Nice
View more
  • x
  • convention:

12
Back to list

Comment

You need to log in to comment to the post Login | Register
Comment

Notice: To protect the legitimate rights and interests of you, the community, and third parties, do not release content that may bring legal risks to all parties, including but are not limited to the following:
  • Politically sensitive content
  • Content concerning pornography, gambling, and drug abuse
  • Content that may disclose or infringe upon others ' commercial secrets, intellectual properties, including trade marks, copyrights, and patents, and personal privacy
Do not share your account and password with others. All operations performed using your account will be regarded as your own actions and all consequences arising therefrom will be borne by you. For details, see " User Agreement."

My Followers

Login and enjoy all the member benefits

Login

Block
Are you sure to block this user?
Users on your blacklist cannot comment on your post,cannot mention you, cannot send you private messages.
Reminder
Please bind your phone number to obtain invitation bonus.
Information Protection Guide
Thanks for using Huawei Enterprise Support Community! We will help you learn how we collect, use, store and share your personal information and the rights you have in accordance with Privacy Policy and User Agreement.