Maven實際上是一個插件容器。
Maven實際上是一個插件容器。...
我們可以使用Maven插件:
我們可以使用以下語法來執(zhí)行插件及其目標。
mvn [plugin-name]:[goal-name]
以下代碼使用maven-compiler-plugin的compile-goal編譯Java項目。
mvn compiler:compile
Maven提供了以下兩種類型的插件:
類型 | 描述 |
---|---|
描述... | 在構建期間執(zhí)行,并且應該進行配置在< build /> 元素。 |
在構建期間執(zhí)行,并且應該進行配置在< build /> 元素。... | 在站點生成期間執(zhí)行它們應在< reporting /> 元素。 |
下表列出了幾個常見插件。
插入 | 描述 |
---|---|
clean | 在站點生成期間執(zhí)行它們應在< reporting /> 元素。... |
compiler | |
編譯Java源。 | |
deploy | 編譯Java源。... |
failsafe | 在隔離的類加載器中運行JUnit測試。 |
install | 在隔離的類加載器中運行JUnit測試。... |
resources | 將資源復制到輸出目錄以包括在JAR中。 |
site | 為當前項目生成站點。 |
ear | 從當前項目生成EAR。 |
以下pom.xml文件顯示如何配置執(zhí)行以輸出文本。
<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> <groupId>com.java2s.project</groupId> <artifactId>simpleCode</artifactId> <version>1.0</version> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.1</version> <executions> <execution> <id>id.clean</id> <phase>clean</phase> <goals> <goal>run</goal> </goals> <configuration> <tasks> <echo>hi from plugin.</echo> </tasks> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
將上面的代碼保存到c:\\ mvn_test,打開命令控制臺和請轉到c:\\ mvn_test執(zhí)行以下mvn命令。
C:\mvn_text>mvn clean
更多建議: