有用的maven插件

Posted sunbylm

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了有用的maven插件相关的知识,希望对你有一定的参考价值。

摘要:本文介绍maven的几个重要的插件:解压压缩包的插件(maven-dependency-plugin)、复制,删除,移动文件插件(maven-antrun-plugin)、执行任务插件(exec-maven-plugin)、打war包插件(maven-war-plugin)、打jar包插件(maven-jar-plugin)、打源码包插件(maven-source-plugin)。

--------------------------------------------------------解压压缩文件war(maven-dependency-plugin)--------------------------------------------------------------------------

一、解压压缩文件war(maven-dependency-plugin)

<!--解压文件-->
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <executions>
    <execution>
      <id>unpack</id>
      <phase>process-sources</phase>
      <goals>
        <goal>unpack</goal>
      </goals>
      <configuration>
        <artifactItems>
          <!-- 解压 ${test-artifactId}-${test-version}.war包-->
          <artifactItem>
            <groupId>com.hikvision</groupId>
            <artifactId>${test-artifactId}</artifactId>
            <version>${test-version}</version>
            <type>war</type>
            <classifier>war</classifier>
            <overWrite>true</overWrite>
            <outputDirectory>${resource-webapp}/${test-context}</outputDirectory>
            <includes>**/*.*</includes>
            <excludes>**/maven/,**/lib/</excludes>
          </artifactItem>
          <!-- 解压${test1-artifactId}-${test1-version}.war包-->
          <artifactItem>
            <groupId>com.hikvision</groupId>
            <artifactId>${test1-artifactId}</artifactId>
            <version>${test1-version}</version>
            <type>war</type>
            <overWrite>true</overWrite>
            <outputDirectory>${resource-webapp}/${test1-context}</outputDirectory>
            <includes>**/*.*</includes>
            <excludes>**/maven/,**/lib/</excludes>
          </artifactItem>
        </artifactItems>
      </configuration>
    </execution>
  </executions>
</plugin>

---------------------------------------------------------------------复制,删除,移动文件插件(maven-antrun-plugin)----------------------------------------------------------

二、复制,删除,移动文件插件(maven-antrun-plugin)

<!--拷贝文件-->
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-antrun-plugin</artifactId>
  <version>1.8</version>
  <executions>
    <execution>
      <id>copy</id>
      <phase>generate-resources</phase>
      <goals>
        <goal>run</goal>
      </goals>
      <configuration>
        <tasks>
          <!-- 复制 -->
          <copy todir="${test-webapp}/META-INF" overwrite="true">
            <fileset dir="${test-webapp}/${test-context}/META-INF" />
            <fileset dir="${test1-webapp}/${test1-context}/META-INF" />
          </copy>

          <delete dir="${test-webapp}/${test-context}/META-INF"/>
          <move file="${test-webapp}/${test-context}/WEB-INF/classes/version.properties" tofile="${test-webapp}/WEB-INF/classes/version/test.properties"/>
          <move todir="${resource-webapp}/${br-context}">
            <fileset dir="${resource-webapp}/${br-context}/${br-context}"/>
          </move>
          <copyfile src="${test-webapp}/${test-context}/fav.ico" dest="${test-webapp}/fav.ico"/>
        </tasks>
      </configuration>
    </execution>
  </executions>
</plugin>

---------------------------------------------------------------------------执行任务插件(exec-maven-plugin)-------------------------------------------------------------------------

三、执行任务插件(exec-maven-plugin)

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <version>1.1.1</version>
  <executions>
    <execution>
      <id>genVersion</id>
      <phase>compile</phase>
      <goals>
        <goal>java</goal>
      </goals>
      <configuration>
        <mainClass>com.test.core.utils.svn.SVNVersionBuild</mainClass>
        <arguments>
          <argument>test</argument>
          <argument>8.2.0</argument>
        </arguments>
      </configuration>
    </execution>
  </executions>
</plugin>

备注:com.test.core.utils.svn.SVNVersionBuild是一个java类,该类有main方法,同时该main方法需要两个参数。

---------------------------------------------------------------------------打war包插件(maven-war-plugin)-------------------------------------------------------------------------------

四、打war包插件(maven-war-plugin)

<pluginManagement>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-war-plugin</artifactId>
      <version>2.3</version>
    </plugin>
  </plugins>
</pluginManagement>

































































































以上是关于有用的maven插件的主要内容,如果未能解决你的问题,请参考以下文章

maven常用插件整理

Tomcat 9 的 Maven 插件

eclipse使用git插件导入码云上的maven工程

禁用父 POM 中定义的 Maven 插件

通过 Maven 前端插件或通过命令行选项从“npm install”输出调试到文件?

eclipse maven插件如何添加maven插件,pom里面应该怎么写