2015-10-19 81 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