11.7. Maven plug-in

发布时间 : 2025-10-25 13:35:08 UTC      

Page Views: 9 views

Maven has three standard lifecycles:

  • clean : handling of project cleanup

  • default(或 build) Processing of project deployment

  • site Processing of project site document creation

Each lifecycle contains a series of phases (phase). These phase are equivalent to the unified interface provided by Maven, and then the implementation of these phase is done by Maven plug-ins.

When we enter the mvn command, such as mvn clean,clean, it corresponds to the clean phase in the Clean life cycle. But the specific operation of clean is made up of maven-clean-plugin To make it happen.

So the concrete implementation of each phase of the Maven life cycle is implemented by the Maven plug-in.

Maven is actually a framework that relies on plug-ins for execution, and each task is actually done by plug-ins. The Maven plug-in is usually used to:

  • Create a jar file

  • Create a war file

  • Compile code file

  • Code unit test

  • Create a project document

  • Create a project report

Plug-ins usually provide a collection of targets and can be executed using the following syntax:

<code>mvn [plugin-name]:[goal-name]code>    

For example, a Java project can be compiled using maven-compiler-plugin ‘s compile-goal, using the following command:

<code>mvn compiler:compilecode>    

11.7.1. Plug-in type

Maven provides the following two types of plug-ins:

Types

Description

Build plugins

It is executed at build time and configured in the element of pom.xml.

Reporting plugins

It is executed during the site generation process and configured in the element of pom.xml.

Here is a list of some common plug-ins:

Plug-in

Description

Clean

Clean up the target file after building. Delete the destination directory.

Compiler

Compile the Java source file.

Surefile

Run the JUnit unit test. Create a test report.

Jar

Build the JAR file from the current project.

War

Build the WAR file from the current project.

Javadoc

Generate Javadoc for the project.

Antrun

Run a collection of ant tasks from any stage of the build process.

11.7.2. Example

We’ve used it a lot in our example. maven-antrun-plugin To output the data to the console. Please check Maven - 构建配置文件 Chapter. Let’s understand this section in a better way and create a pom.xml file in the C:MVNproject directory.

<projectxmlns="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">4.0.0com.companyname.projectgroupproject1.0org.apache.maven.pluginsmaven-antrun-plugin1.1id.cleancleanrunclean phaseecho>tasks>configuration>execution>executions>plugin>plugins>build>project>    

Next, open the command terminal and jump to the directory where pom.xml is located, and execute the following mvn command.

mvn clean 

Maven will begin to process and display the clean phase of the clean life cycle.

[INFO] Scanning for projects... [INFO] ------------------------------------------------------------------ [INFO] Building Unnamed - com.companyname.projectgroup:project:jar:1.0 [INFO] task-segment: [post-clean] [INFO] ------------------------------------------------------------------ [INFO] [clean:clean {execution: default-clean}] [INFO] [antrun:run {execution: id.clean}] [INFO] Executing tasks [echo] clean phase [INFO] Executed tasks [INFO] ------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------ [INFO] Total time: < 1 second [INFO] Finished at: Sat Jul 07 13:38:59 IST 2012 [INFO] Final Memory: 4M/44M [INFO] ------------------------------------------------------------------ 

The above example shows the following key concepts:

  • Plug-ins are defined using the plugins element in pom.xml.

  • Each plug-in can have multiple goals.

  • You can define the phase, and the plug-in will use its phase element to start processing. We’ve used it. clean Stage.

  • You can configure the tasks to be performed by binding to the target of the plug-in. We’re already bound. echo Task to maven-antrun-plugin run target.

  • That’s it. Maven will take care of the rest. It will download plug-ins that are not available in the local repository and start processing.

《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。