<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Sky's blog

    我和我追逐的夢

    常用鏈接

    統計

    其他鏈接

    友情鏈接

    最新評論

    初學maven(5)-使用assembly plugin實現自定義打包

        在上一篇文章中,討論到在對maven的機制不熟悉的情況下,為了實現自己需要的打包格式而使用maven ant task以maven + ant的方式來實現非標準打包,而現在要介紹的是maven中針對打包任務而提供的標準插件:assembly plugin。

        依然以上文(初學maven(4)-使用maven ant task實現非標準打包)的項目為例,要打包的程序如下:

        demo1
        |____lib
        |_____demo1.jar
        |_____*****.jar
        |_____*****.jar
        |____config
        |_____*****.properties
        |_____*****.xml
        |____log
        |_____*****.log
        |____run.bat
        |____run.sh

        類似的建立java項目,文件結構如下:

        demo1
        |____src/main/java
        |____src/main/config
        |____src/main/bin
        |____src/main/resources
        |____src/main/assemble
        |____src/test/java
        |____src/test/resources
        |____target
        |____pom.xml

        除開增加了src/main/assemble目錄和沒有ant的build文件外,其他內容完全一樣:其中src/main/java下放java代碼;src/main/resources下放一個*.properties文件,這個資源文件是打包到 jar中,內容打包之后不需要改變的。src/main/config下放一個標準的log4j.xml,這個是有在安裝運行前臨時修改的需要的。src /main/bin下放置可執行文件。

        assembly plugin的使用方式比較簡單,主要有:

    1. 修改pom.xml

        pom.xml中設置如下:
       
    <build>
            
    <plugins>
                
    <plugin>
                    
    <artifactId>maven-assembly-plugin</artifactId>
                    
    <configuration>
                        
    <!-- not append assembly id in release file name -->
                        
    <appendAssemblyId>false</appendAssemblyId>
                        
    <descriptors>
                            
    <descriptor>src/main/assemble/package.xml</descriptor>
                        
    </descriptors>
                    
    </configuration>
                    
    <executions>
                        
    <execution>
                            
    <id>make-assembly</id>
                            
    <phase>package</phase>
                            
    <goals>
                               
    <goal>single</goal>
                            
    </goals>
                        
    </execution>
                    
    </executions>
                
    </plugin>
            
    </plugins>
        
    </build>

        其中<artifactId>maven-assembly-plugin</artifactId>的maven-assembly-plugin是這個插件的標準命名,在maven2.0.*中帶的默認版本是

        appendAssemblyId屬性控制是否在生成的打包文件的文件名中包含assembly id。
       
        descriptor屬性指定maven-assembly-plugin的配置文件,當然我設置的是src/main/assemble/package.xml.容許使用多個,功能強大當然用法也復雜,對于簡單情況一個足矣。

        execution的設置是為了將maven-assembly-plugin繼承到標準的maven打包過程中,這樣在運行maven-package時就會執行maven-assembly-plugin的操作,從而實現我們需要的自定義打包。
    2. assemble descriptor file

        我的src/main/assemble/package.xml內容如下:

    <assembly 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/assembly-1.0.0.xsd">
        
    <id>package</id>
        
    <formats>
            
    <format>zip</format>
        
    </formats>
        
    <includeBaseDirectory>true</includeBaseDirectory>
        
    <fileSets>
            
    <fileSet>
                
    <directory>src/main/bin</directory>
                
    <outputDirectory>/</outputDirectory>
            
    </fileSet>
            
    <fileSet>
                
    <directory>src/main/config</directory>
                
    <outputDirectory>config</outputDirectory>
            
    </fileSet>
        
    </fileSets>
        
    <dependencySets>
            
    <dependencySet>
                
    <outputDirectory>lib</outputDirectory>
                
    <scope>runtime</scope>
            
    </dependencySet>
        
    </dependencySets>
    </assembly>

       
        詳細的語法不介紹了,請參考官方指南,有非常詳盡的說明:Assembly Descriptor Format reference

        簡單解釋一下:

        1) format
        format=zip設置打包的最終文件格式為zip.
        支持的其他格式還有gz,tar,tar.gz,tar.bz2。

        2)  fileset
       
        <fileSet>
                
    <directory>src/main/bin</directory>
                
    <outputDirectory>/</outputDirectory>
        
    </fileSet> 
     
        將src/main/bin目錄下的文件打包到根目錄(/)下.

    <fileSet>
                
    <directory>src/main/config</directory>
                
    <outputDirectory>config</outputDirectory>
    </fileSet>

        將src/main/config目錄下的文件打包到config下.

        3) dependencySets

        <dependencySet>
                
    <outputDirectory>lib</outputDirectory>
                
    <scope>runtime</scope>
       
    </dependencySet>

        將scope為runtime的依賴包打包到lib目錄下。


        總結一下,pom.xml中引入maven-assembly-plugin,然后assemble descriptor file按需設置,最后在eclipse中執行Run As -> Maven package,在target目錄下就會出現***.zip文件,里面的格式和要求的完全一致。

        夠簡單明了吧?感覺比使用maven ant task要輕快不少,看來maven還是很強大的,繼續學習......

    posted on 2009-01-16 18:22 sky ao 閱讀(49315) 評論(1)  編輯  收藏 所屬分類: project building

    評論

    # re: 初學maven(5)-使用assembly plugin實現自定義打包 2016-04-25 09:14 李金龍

    按照你這種配置,執行mvn compile,config里面的文件夾不會復制到classes里面,所以在測試的時候也要打包才行?  回復  更多評論   

    主站蜘蛛池模板: 丝袜捆绑调教视频免费区| 久久亚洲最大成人网4438| 另类图片亚洲校园小说区| 91嫩草国产在线观看免费| 亚洲成在人天堂一区二区| 一区二区三区在线免费观看视频 | 亚洲精品狼友在线播放| a级片免费在线观看| 亚洲AV无码久久| 国产高清免费视频| 亚洲一线产区二线产区区| 成年女人永久免费观看片| 免费夜色污私人影院网站电影| 亚洲国产成人久久综合野外| free哆拍拍免费永久视频| 亚洲精品美女久久777777| 99re6在线精品视频免费播放| 亚洲国产精品久久人人爱| 成人免费午夜无码视频 | 美女免费精品高清毛片在线视| 亚洲综合色成在线播放| 免费成人高清在线视频| 亚洲入口无毒网址你懂的| 四虎永久在线免费观看| 99在线免费观看| 亚洲国语在线视频手机在线| 四虎影视www四虎免费| 巨胸喷奶水视频www免费视频| 亚洲影院在线观看| 高清国语自产拍免费视频国产| 一个人免费播放在线视频看片| 亚洲日韩图片专区第1页| 午夜影视在线免费观看| 一区二区三区免费视频播放器| 91天堂素人精品系列全集亚洲 | 免费能直接在线观看黄的视频| 处破女第一次亚洲18分钟| 九月丁香婷婷亚洲综合色| 女人18毛片特级一级免费视频 | 美女裸身网站免费看免费网站| 十八禁的黄污污免费网站|