2015-10-19 46 views
0

我已經將依賴項jar放在單獨的文件夾中,但期望文件夾應該壓縮而不是直接文件夾。我嘗試使用組裝描述符,但它創建單獨的文件夾與依賴關係,但不壓縮它(文件夾不應該在那裏,只有zip文件預計)。請建議我更好的辦法,以適應我的依賴罐子在一個zip文件包在一個zip文件中提供了依賴關係

的pom.xml

<build> 
    <plugins> 
     <plugin> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <configuration> 
       <source>1.7</source> 
       <target>1.7</target> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-dependency-plugin</artifactId> 
      <version>2.9</version> 

      <executions> 
       <execution> 
        <id>copy-dependencies</id> 
        <phase>package</phase> 
        <goals> 
         <goal>copy-dependencies</goal> 
        </goals> 
        <configuration> 
         <includeScope>provided</includeScope> 
         <outputDirectory>/Users/venugopal/Documents/providedDependencies</outputDirectory> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <configuration> 
       <descriptors> 
        <descriptor>src/assembly/archive_format.xml</descriptor> 
       </descriptors> 
      </configuration> 
      <executions> 
       <execution> 
        <id>make-assembly</id> <!-- this is used for inheritance merges --> 
        <phase>package</phase> <!-- append to the packaging phase. --> 
        <goals> 
         <goal>single</goal> <!-- goals == mojos --> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

archive_format.xml(裝配描述

<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>bin</id> 
    <baseDirectory>/</baseDirectory> 
    <formats> 
    <format>zip</format> 
    </formats> 
    <fileSets> 
    <fileSet> 
     <directory>/Users/vp/Documents/providedDependencies</directory> 
    </fileSet> 
    </fileSets> 
</assembly> 
+0

我只需要特定的作用域依賴關係(提供作用域)作爲zip – user439587

回答

1

如果我理解你的要求的權利,你想打包所有提供的依賴關係到一個zip文件。

你用錯誤的方式使用maven-dependency-plugin。您應該使用maven-assembly-plugin及其dependencySet

<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>bin</id> 
    <baseDirectory>/</baseDirectory> 
    <formats> 
    <format>zip</format> 
    </formats> 
    <dependencySets> 
    <dependencySet> 
     <scope>provided</scope> 
     <outputDirectory>/</outputDirectory> 
     <useProjectArtifact>false</useProjectArtifact> 
    </dependencySet> 
    </dependencySets> 
</assembly> 

範圍設置爲provided將確保只有提供的依賴都在該集合考慮。我們需要排除項目工件,否則它將默認包含在內。

+0

上面的代碼是示例,實際項目有超/父pom.xml並具有多個webapps.Objective是所有webapps提供的作用域移動到單個zip文件。請提供使用程序集描述符配置父pom.xml的詳細信息 – user439587

+0

上面的代碼工作正常,如果只有/。當我嘗試提供外部位置時,沒有顯示任何內容 – user439587

+0

幫助我保持所有webapps jar移動到單個郵編 – user439587

相關問題