包含maven程序集插件的特定依赖项

时间:2015-01-29 18:26:00

标签: java maven pom.xml

我正在使用maven程序集插件,以便我可以包含特定的依赖项(基本上我想要 在我的jar文件中包含特定的传递依赖项。以下是pom.xml -

中的相关代码段
<build>
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
                <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
      </plugin>  

      </plugins>
  </build> 

通过链接http://maven.apache.org/plugins/maven-assembly-plugin/advanced-descriptor-topics.html看起来是可行的  但是,下面提到下面的代码片段,包括两种类型的依赖项com.companyA。*和com.companyB。*,除外  我不想排除所有其他依赖项

<dependencySets>
    <dependencySet>
      <includes>
        <include>com.companyA.*</include>
        <include>com.companyB.*</include>
      </includes>
    </dependencySet>
  </dependencySets>

但是pom.xml依赖内容的无效内容。我不知道如何在这里实现目标?

2 个答案:

答案 0 :(得分:0)

我通常使用具有互斥模式的两个<dependencySet>条目,如此

<dependencySet>
  <outputDirectory>lib</outputDirectory>
  <scope>runtime</scope>
  <excludes>
    <exclude>com.mypkg.*:*</exclude>
  </excludes>
</dependencySet>

<dependencySet>
  <outputDirectory>bin</outputDirectory>
  <scope>runtime</scope>
  <includes>
    <include>com.mypkg.*:*</include>
  </includes>
</dependencySet>

在这种情况下,它会将com.mypkg中的所有内容复制到bin文件夹,而将com.mypkg的所有内容复制到lib文件夹

这种方法应该足以满足您的目标

答案 1 :(得分:0)

我认为您对我也有同样的问题。在这里,您只能像这样在pom.xml中进行部分配置:

<plugin>    
              <artifactId>maven-assembly-plugin</artifactId>    
              <configuration>    
                    <descriptors>    
                        <descriptor>assembly.xml</descriptor>    
                   </descriptors>    
              </configuration>    
                <executions>  
                    <execution>  
                        <phase>install</phase>  
                        <goals>  
                            <goal>single</goal>  
                        </goals>  
                        <configuration>  
                            <outputDirectory>d:/temp/stock</outputDirectory>  
                        </configuration>  
                    </execution>  
                </executions>  

         </plugin>  

但是您可以在assembly.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>jar-with-dependencies</id>  
    <formats>  
        <format>dir</format>  
    </formats>  
    <includeBaseDirectory>false</includeBaseDirectory>  
    <dependencySets>  
        <dependencySet>  
            <useProjectArtifact>true</useProjectArtifact>  
            <outputDirectory>/</outputDirectory>  
            <includes>  
                <include>org.tkxing.stock:org.tkxing.stock.test</include>  
            </includes>         
        </dependencySet>  
        <dependencySet>  
            <useProjectArtifact>false</useProjectArtifact>  
            <outputDirectory>lib/</outputDirectory>  
            <excludes>  
                <exclude>org.springframework:spring-beans</exclude>  
                <exclude>org.springframework:spring-asm</exclude>  
                <exclude>org.springframework:spring-core</exclude>  
                <exclude>org.springframework:spring-aop</exclude>  
                <exclude>org.springframework:spring-context</exclude>  
                <exclude>org.springframework:spring-expression</exclude>  
                <exclude>org.springframework:spring-jms</exclude>  
                <exclude>org.springframework:spring-tx</exclude>  
            </excludes>  
        </dependencySet>  
    </dependencySets>  

    <fileSets>  
        <fileSet>  
            <directory>conf</directory>  
            <outputDirectory>conf</outputDirectory>  
        </fileSet>  
        <fileSet>  
            <directory>bundles</directory>  
            <outputDirectory>bundles</outputDirectory>  
        </fileSet>  
    </fileSets>  

    <files>  
        <file>  
            <source>log4j.xml</source>  
            <outputDirectory>/</outputDirectory>  
        </file>  
    </files>  

</assembly>  

希望这可以帮助其他人

相关问题