In Maven how to exclude resources from the generated jar?

后端 未结 8 1115
余生分开走
余生分开走 2020-11-30 01:46

When I create an executable jar with dependencies (using this guide), all properties files are packaged into that jar too. How to stop it from happening? Thanks.

UPD

相关标签:
8条回答
  • 2020-11-30 02:19

    Another possibility is to use the Maven Shade Plugin, e.g. to exclude a logging properties file used only locally in your IDE:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>${maven-shade-plugin-version}</version>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>shade</goal>
                </goals>
                <configuration>
                    <filters>
                        <filter>
                            <artifact>*:*</artifact>
                            <excludes>
                                <exclude>log4j2.xml</exclude>
                            </excludes>
                        </filter>
                    </filters>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    This will however exclude the files from every artifact, so it might not be feasible in every situation.

    0 讨论(0)
  • 2020-11-30 02:22

    Exclude specific pattern of file during creation of maven jar using maven-jar-plugin.

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jar-plugin</artifactId>
      <version>2.3</version>
      <configuration>
        <excludes>
          <exclude>**/*.properties</exclude>
          <exclude>**/*.xml</exclude>
          <exclude>**/*.exe</exclude>
          <exclude>**/*.java</exclude>
          <exclude>**/*.xls</exclude>
        </excludes>
      </configuration>
    </plugin>
    
    0 讨论(0)
提交回复
热议问题