`

maven-assembly-plugin 配置技巧

阅读更多
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/wolffool/archive/2011/03/24/6275722.aspx

一、有时web工程的静态文件(image/css/js)希望独立部署,需要针对静态内容打包。可通过以下配置:


<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <version>2.2</version> 
    <executions> 
      <execution> 
        <id>make-assembly</id> 
        <phase>package</phase> 
        <goals> 
          <goal>single</goal> 
        </goals> 
        <configuration> 
          <descriptors> 
            <descriptor>src/assemble/statics-zip.xml</descriptor> 
          </descriptors> 
        </configuration> 
      </execution> 
    </executions> 
</plugin> 

当然,另外还需手工编写相应的src/assemble/statics-zip.xml文件,以配置zip文件中的内容:



<?xml version="1.0" encoding="UTF-8"?> 
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"   
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"> 
    <id>statics</id> 
    <formats><format>zip</format></formats> 
    <includeBaseDirectory>false</includeBaseDirectory> 
    <fileSets> 
        <fileSet> 
          <directory>${basedir}/src/main/webapp/statics-gen</directory> 
          <outputDirectory>statics</outputDirectory> 
        </fileSet> 
    </fileSets> 
</assembly> 

二、 当web工程的静态内容独立部署时,相应的war中可以不再需要包含相应的静态内容。可通过以下配置排除:


    <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-war-plugin</artifactId> 
        <version>2.1.1</version> 
<configuration> 
  <packagingExcludes>statics/**,statics-gen/**</packagingExcludes> 
</configuration> 
    </plugin>  

三、有时希望在jar/war包中,写入当前的SVN revision ,以准确对应SVN中的版本。可先通过以下配置获取当前SVN 版本号:


    <plugin> 
        <groupId>com.google.code.maven-svn-revision-number-plugin</groupId> 
        <artifactId>maven-svn-revision-number-plugin</artifactId> 
        <version>1.6</version> 
<executions> 
    <execution> 
        <goals> 
            <goal>revision</goal> 
        </goals> 
    </execution> 
</executions> 
<configuration> 
    <entries> 
        <entry> 
            <prefix>SVN</prefix> 
        </entry> 
    </entries> 
</configuration> 
    </plugin> 

再将SVN版本号写入war包中:


    <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-war-plugin</artifactId> 
        <version>2.1.1</version> 
<configuration> 
  <archive> 
    <manifestEntries> 
      <SVN-Revision>${SVN.revision}</SVN-Revision> 
    </manifestEntries> 
  </archive> 
</configuration> 
    </plugin> 


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics