【问题标题】:Excluding .xml and properties from standalone JAR with spring-boot-maven-plugin使用 spring-boot-maven-plugin 从独立 JAR 中排除 .xml 和属性
【发布时间】:2018-02-17 16:31:38
【问题描述】:

我有一个独立的 JAR maven/spring boot 应用程序。它目前在 /src/main/resources/ 的 JAR 中有 applicationContext.xml 和 application.properties 文件。为了能够在不重新部署的情况下轻松重新配置,我想将 .xml 文件和 .properties 文件移到 jar 之外。

我已经设置了 maven-antrun-plugin,所以它将这些资源复制到目标目录中。

但是,我很难将这两个文件(.xml 和 .properties)从我的 JAR 文件中排除。

我进行了一些研究,大多数指南或讨论都在谈论将排除项添加到 maven-jar-plugin 中,但我没有使用 maven-jar-plugin。有没有办法用 spring-boot-maven-plugin 做到这一点?

我已尝试将以下内容放入我的 pom 文件的“构建”部分:

        <resources>
        <resource>
            <directory>src/main/resources</directory>
            <excludes>
                <exclude>**/*.xml</exclude>
                <exclude>**/*.properties</exclude>
            </excludes>
        </resource>
    </resources>

但是这些文件仍然出现在 maven 构建的 JAR 文件的 /classes 文件夹中。

关于如何做到这一点的任何想法或建议?

【问题讨论】:

    标签: java spring maven spring-boot jar


    【解决方案1】:

    您发布的 sn-p 应该正是这样做的。您可以通过使用命令mvn -X install 构建项目来验证是否使maven 进程更详细。此命令应产生类似

    的输出

    [DEBUG] 配置 mojo 'org.apache.maven.plugins:maven-resources-plugin ...

    并且应显示排除文件下方的一些行。

    不包括 [**/*.xml, **/*.properties]

    但我想知道排除这些文件是否是允许配置应用程序的好方法。这个文件真的很基础。也许将文件保存在 jar 中并提供一些有用的默认值会更好。部署后,您可以按照this guide 以不同的优先级覆盖该值。

    【讨论】:

      猜你喜欢
      • 2019-08-12
      • 2014-12-31
      • 1970-01-01
      • 1970-01-01
      • 2013-07-07
      • 2018-02-16
      • 1970-01-01
      • 1970-01-01
      • 2014-11-22
      相关资源
      最近更新 更多