简体   繁体   English

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

[英]How to exclude package in jar by editing pom.xml?

I'm trying to exclude a package in the jar(maven dependency) by editing pom.xml 我正在尝试通过编辑pom.xml来排除jar中的包(maven依赖)

So I tried some ways that adding tag in the , using maven-shade-plugin, and using maven-jar-plugin. 所以我尝试了一些方法,使用maven-shade-plugin和maven-jar-plugin添加标签。 But it didn't work. 但它没有用。 Package in the jar still exists. jar中的包仍然存在。

Here're codes I tried. 这是我试过的代码。 Thanks. 谢谢。 artifact is jar name, com.domain.package is package to delete form 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>

You can define configuration in your maven jar plugin execution to exclude and include files. 您可以在maven jar插件执行中定义配置以排除和包含文件。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM