java - 使用 Maven 程序集插件包含特定依赖项

标签 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显示依赖集内容无效。我不知道如何实现这里的目标?

最佳答案

我想你和我有同样的问题。这里你只能在 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>  

希望这可以帮助其他人

关于java - 使用 Maven 程序集插件包含特定依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28221899/

相关文章:

java - 如何显示JavaFX TableView中继承的对象

java - 改进 Selenium webdriver 项目的最佳方法是什么

java - gcloud : Default Application Credentials in appengine for Cloud Storage (java)

java - maven 没有正确添加主类

java - 将文本文件安全地存储在 JAR 中

java - libGDX 3D 阴影伪像

java - 运行 java jar 应用程序时如何修复 "java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory"错误

maven 程序集,如果找不到文件则失败

java - 未按预期评估 Maven 属性(os-maven-plugin)

java - 如果满足条件,则将值添加到 HashMap 中的键