如何通过编辑pom.xml在jar中排除软件包?

时间:2019-03-25 08:42:39

标签: java maven

我正在尝试通过编辑pom.xml在jar(maven依赖项)中排除软件包

因此,我尝试了一些方法,使用maven-shade-plugin和maven-jar-plugin在中添加标签。 但这没有用。罐子里的包装仍然存在。

这是我尝试的代码。谢谢。 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>

1 个答案:

答案 0 :(得分:0)

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

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

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