使用spring-boot-maven-plugin从独立的JAR中排除.xml和属性 [英] Excluding .xml and properties from standalone JAR with spring-boot-maven-plugin

查看:1066
本文介绍了使用spring-boot-maven-plugin从独立的JAR中排除.xml和属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在运行的独立JAR Maven/Spring Boot应用程序.当前,它在/src/main/resources/中的JAR中具有applicationContext.xml和application.properties文件.为了易于重新配置而无需重新部署,我想将.xml文件和.properties文件移到jar之外.

I have a working standalone JAR maven/spring boot app. It currently has its applicationContext.xml and application.properties files in the JAR within /src/main/resources/. For the sake of easily being able to reconfigure without redeploying, I would like to move the .xml file and the .properties file outside of the jar.

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

I've setup the maven-antrun-plugin so it copies those resources into the target directory.

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

However, I'm having difficulty getting these two files (.xml and .properties) excluded from my JAR file.

我已经做过一些研究,大多数指南或讨论都谈到将排除项添加到maven-jar-plugin中,但是我没有使用maven-jar-plugin.有没有办法用spring-boot-maven-plugin来做到这一点?

I've done some research and most guides or discussions talk about adding exclusions into the maven-jar-plugin, but I'm not using maven-jar-plugin. Is there a way to do this with spring-boot-maven-plugin?

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

I've tried putting the following in my "build" section of my pom file:

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

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

But the files are still appearing in the /classes folder in the JAR file that maven builds.

关于如何执行此操作的任何想法或建议?

Any thoughts or advice as to how to do this?

推荐答案

您发布的摘录应完全做到这一点.您可以通过使用命令mvn -X install来构建项目,从而验证是否使Maven流程更加冗长.此命令应产生类似

Your posted snippet should exactly do that. You can verify that if you make the maven processes more verbose, probably by building your project with the command mvn -X install. This command should produce an output like

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

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

,并且应该显示排除文件下方的一些行.

and some lines below the excluded files should be shown.

排除[**/*.xml,**/*.properties]

excludes [**/*.xml, **/*.properties]

但是我不知道是否仅排除此文件是允许配置您的应用程序的好方法.这个文件真的很基础.最好将文件保留在jar中并提供一些有用的默认值.部署后,您可以通过遵循本指南.

But I wonder if just excluding this files is a good way to allow to configure your application. This files are really fundamental. Maybe it would be a better idea to keep the files within the jar and provide some useful defaults. After deployment you can override the value with a different precedence by following this guide.

这篇关于使用spring-boot-maven-plugin从独立的JAR中排除.xml和属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆