You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Maven profile配置下jar包资源文件排除规则不生效如何解决?

解决方案
  • 确认Profile已激活
    打开IDEA右侧Maven面板,展开「Profiles」分类,勾选你配置的对应id的profile选项,修改pom.xml后必须点击Maven面板的刷新按钮同步配置。如果使用命令行构建,需要添加-P参数指定激活的profile,比如mvn clean package -Pprofile。
  • 优先使用maven-jar-plugin配置排除规则
    如果直接在profile的节点配置排除不生效,大概率是全局下的资源配置和profile内的配置产生了冲突,推荐直接在打jar包阶段配置排除规则,优先级更高不会冲突,示例配置如下:
<profiles>
    <profile>
        <id>profile</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>3.2.2</version>
                    <configuration>
                        <excludes>
                            <exclude>**/abc.txt</exclude>
                        </excludes>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

如果还是要使用节点配置,需要保证profile内的资源配置完整指定目录、过滤规则等参数,示例如下:

<profiles>
    <profile>
        <id>profile</id>
        <build>
            <resources>
                <resource>
                    <directory>${project.basedir}/src/main/resources</directory>
                    <excludes>
                        <exclude>**/abc.txt</exclude>
                    </excludes>
                    <filtering>true</filtering>
                </resource>
            </resources>
        </build>
    </profile>
</profiles>

内容的提问来源于stack exchange,提问作者bruno grznar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.05 16:06:02