Deep SSH adventure (4) What is Maven preliminary?

Source: Internet
Author: User

I have been familiar with this word for many times over the past few days. I just realized its advantages in gxpt and its powerful functions. I also learned more about it through searching materials on the Internet, share with you.


Maven is a software project management tool based on the project Object Model (POM). It can use a short section to describe information to manage project construction, reports, and documents.



Implementation in gxpt


1. A multi-module project of parent-child relationship is defined by one parent pom referencing one or more sub-modules. A. Create a sub-project in the parent folder. B. Create a parent project and associate the sub-project with the following configuration: for example:
<span style="font-size:18px;"><span style="font-size:18px;"><modules><module>../gxpt_entity_uas</module> <module>../gxpt_common_tool</module> <module>../gxpt_common_eao_impl</module> <module>../gxpt_mgr_uas_fee</module> <module>../gxpt_mgr_uas_fee_impl</module> <module>../gxpt_web_uas_fee</module> <module>../gxpt_common_eao</module> </modules></span></span>
<span style="font-size:18px;"><span style="font-size:18px;"><packaging>pom</packaging></span></span>

Where: In the modules element, each modules element corresponds to a sub-folder under the parent folder. Maven searches for the Pom. xml file in these subfolders, and includes these submodules in the project to be built when building mydemo.
In addition, the configuration of <packaging> pom </packaging> indicates that this parent project does not create a jar or a war as in the previous project, but a pom that references other Maven projects. The lower part of POM. xml lists the sub-modules of the project.
C. Add? Parent Project Association:

<span style="font-size:18px;"><span style="font-size:18px;"><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/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>com.tgb</groupId><artifactId>gxpt</artifactId><version>0.0.1-SNAPSHOT</version><relativePath>../gxpt/pom.xml</relativePath></parent></span></span>

2. Dependency assume that there is a dependency between projects. For example, if project a depends on Project B, you must add? The dependency node <dependency> of B, indicating that the jar package of B is required in Project.


Maven Lifecycle)

One important reason why Maven is powerful is that it has a very good lifecycle model, which can be understood in two aspects. First, as the name suggests, every step of executing Maven is defined by it. The default behavior defined in advance makes it easy for us to use maven. In comparison, You need to manually define every step of ant. Second, this model is a standard. In different projects, the maven interface is the same, so that you do not need to carefully understand the construction of each project. In general,MVN clean installThis command is common. I think, it must have absorbed a lot of project experience, and Maven can define such a good model.

 

Maven has three sets of independent lifecycles. Note that the three sets are described as "Three sets" and "independent of each other ", the person who just started learning easy regards Maven's life cycle as a whole. In fact, it is not. The three lifecycles are respectively:

  • Clean lifecycle does some cleanup work before the actual build.
  • Core Part of default lifecycle construction, compilation, testing, packaging, deployment, and so on.
  • Site lifecycle generates project reports, websites, and websites.

 

After knowing the general purpose and relationship of each set of lifecycle, let's take a look at each set of lifecycles one by one. The comparison between clean and site is simple. Let's explain it first.

 

Each set of lifecycle consists of a set of phases (phase). The commands we input in the command line are always corresponding to a specific stage. For example, executeMVN clean, This clean is a stage of the clean lifecycle. A bit difficult? You must know that there is a clean lifecycle or a clean stage.


The Clean lifecycle consists of three phases:

  • Pre-clean run some work that needs to be completed before clean
  • Clean remove all files generated by the previous build
  • Post-clean: some jobs that need to be completed immediately after the clean operation

MVN cleanThe "clean" in is the above ". In a lifecycle, when a stage is executed, all stages before it will be executed. That is to say,MVN cleanEquivalentMVN pre-Clean cleanAssume that we executeMVN post-cleanIn this case, both pre-clean and clean are executed. This is a very important rule of Maven and can greatly simplify the input of command lines.

 

The following describes the stages of the site lifecycle:

  • Pre-site running must be completed before website documents are generated
  • Site: generate the project's website documents
  • Post-site operations must be completed after website documents are generated, and preparations for deployment
  • Site-Deploy the generated website documents to a specific server

Here, we often use the site and site-deploy stages to generate and publish Maven websites. However, Maven is quite powerful, and managers like Maven, take the initiative to generate documents and statistics.

 

Finally, let's take a look at Maven's most important default life cycle. Most of the work is happening in this life cycle. Here, I only explain some stages that are more important and frequently used than Maven:


  • Validate
  • Generate-Sources
  • Process-Sources
  • Generate-Resources
  • Process-resources: Copy and process resource files to the target folder and prepare for packaging.
  • Compile the source code of the project.
  • Process-classes
  • Generate-test-Sources
  • Process-test-Sources
  • Generate-test-Resources
  • Process-test-resources: Copy and process the resource file to the target worker test folder.
  • Test-compile to compile the test source code.
  • Process-test-classes
  • Test uses the appropriate unit testing framework to perform the testing. These trial code will not be packaged or deployed.
  • Prepare-Package
  • The package accepts compiled code and packs it into a publicly available format, such as jar.
  • Pre-integration-test
  • Integration-test
  • Post-integration-test
  • Verify
  • Install the package to the local repository to make other projects dependent.
  • Deploy copies the final package to a remote repository to share the package with other developers.

Basically, based on the name we can guess the purpose of each stage, for other stages of interpretation, please refer to the http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

 

Remember, no matter what stage of execution, all the stages before it will be executed, that is why we executeMVN installThe code will be compiled, tested, and packaged.

 

In addition, the maven plug-in mechanism is completely dependent on the maven lifecycle, so it is critical to understand the lifecycle. In subsequent articles, I will further explain the maven plug-in mechanism.


Summary

Just getting started, we still need to gradually gain a deep understanding in the project, learn from giants, and grow faster than others. The learning of knowledge is through comparison, A lot of content in gxpt is based on the knowledge of net, which has profound understanding and good results. The cultivation of abstract capabilities is particularly important. Let's look at the bottom layer of the abstract by the teacher and Buddy, the efficiency of software reuse brought about by abstraction is everywhere embodied. Teachers often talk about it. abstraction should not only be said, but also be constantly applied to our actual projects, to do, to do !!!



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.