java - 如何通过编辑pom.xml来排除jar中的包?

标签 java maven

我试图通过编辑 pom.xml 排除 jar 中的包(maven 依赖项)

所以我尝试了一些在 中添加标签、使用 maven-shade-plugin 和使用 maven-jar-plugin 的方法。 但这没有用。 jar 中的包仍然存在。

这是我尝试过的代码。谢谢。 artifact是jar名称,com.domain.package是删除表单jar的包。

<!-- first trial -->
<dependencies>
  <dependency>
    <groupId>Group</groupId>
    <artifactId>artifact</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${basedir}/src/main/webapp/WEB-INF/lib/artifact.jar</systemPath>

    <exclusions>
      <exclusion>
     <groupId>com.domain.package</groupId>
     <artifactId>package</artifactId>
      </exclusion>
    </exclusions>
   </dependency>
</dependencies>

<!-- second trial -->
<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-shade-plugin</artifactId>
   <version>3.2.1</version>
   <executions>
      <execution>
         <phase>package</phase>
         <goals>
            <goal>shade</goal>
         </goals>
         <configuration>
            <artifactSet>
               <excludes>                            
                  <exclude>artifact:com.domain.package</exclude>
               </excludes>
            </artifactSet>
         </configuration>
      </execution>
   </executions>
</plugin>

<!-- third trial -->
<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-jar-plugin</artifactId>
   <version>2.4</version>
   <executions>
      <execution>
         <id>artifact</id>
         <phase>package</phase>
         <goals>
            <goal>jar</goal>
         </goals>
         <configuration>
            <excludes>
               <exclude>**/com/domain/package/*</exclude>
            </excludes>
         </configuration>
      </execution>
   </executions>
</plugin>

最佳答案

您可以在 Maven jar 插件执行中定义配置以排除和包含文件。

<configuration>
          <includes>
            <include>**/service/*</include>
          </includes>

https://maven.apache.org/plugins/maven-jar-plugin/examples/include-exclude.html

关于java - 如何通过编辑pom.xml来排除jar中的包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55333969/

相关文章:

java - 由于 @tmp dir 导致 Jenkins 管道 DSL Maven 错误

java - Android SQLite 只接受 String[] 作为 whereArgs?

java - SQLHelper 的游标返回带指数的数字

java - 从持久存储加载 session 异常,扩展

java - JPA 和 MySQL 映射实体

maven - 如何在 Tomcat 上运行时调试 GWT 应用程序

eclipse - Apache Camel : maven-remote-resources-plugin (goal "process") is ignored by m2e

java - 具有两个数组的方法。如果第一个数组中的值返回不为空,则必须使用其他数组的相应元素作为第二个方法的参数

maven - 如何在 Maven 配置中正确指定 jcenter 存储库?

java - 无法找到属性文件 Java 和 TestNG