码迷,mamicode.com
首页 > 其他好文 > 详细

有用的maven插件

时间:2017-02-16 23:44:52      阅读:327      评论:0      收藏:0      [点我收藏+]

标签:main方法   pil   gem   art   mojo   main   任务   app   code   

摘要:本文介绍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插件

标签:main方法   pil   gem   art   mojo   main   任务   app   code   

原文地址:http://www.cnblogs.com/man-li/p/6407383.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!