我应该将Maven项目的应用程序配置文件放在哪里? [英] Where should I put application configuration files for a Maven project?

查看:665
本文介绍了我应该将Maven项目的应用程序配置文件放在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Maven Application Assembler 插件从中生成独立的可执行文件我的Java专案.该应用程序读取配置文件,包括Spring文件. Application Assembler插件有一个选项(默认情况下处于激活状态),可以将etc/目录添加到应用程序的类路径中,但是我应该怎么做才能让该插件将配置文件复制到该目录中?

I'm using the Maven Application Assembler plugin to generate stand-alone executables from my Java project. The application reads in configuration files, including Spring files. The Application Assembler plugin has an option (activated by default) to add a etc/ directory to the application's classpath, but what should I do to have the plugin copy my configuration files to this directory?

或更笼统地说,不应在工件中打包的应用程序配置文件在Maven中的洁净位置在什么地方?

Or more generally, where is in Maven the kosher location for application configuration files that should NOT be packaged in the artifact?

推荐答案

您还可以使用资源过滤: http://maven.apache.org/guides/getting-started/index .html#How_do_I_filter_resource_files

You can also use resource filtering: http://maven.apache.org/guides/getting-started/index.html#How_do_I_filter_resource_files

打开过滤:

...
<build>
...
<resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
    </resources>
...
</build>
...

在src/main/resources下创建一个文件,例如:application.properties

make a file under src/main/resources like: application.properties

application.properties

application.properties

configprop.1=${param1}
configprop.2=${param2}

然后设置一个配置文件并可能在settings.xml中设置一些属性 根据这是开发还是生产版本来设置不同的属性. 请参阅: http://maven.apache.org/guides/introduction/introduction -to-profiles.html

Then setup a profile and set some properties perhaps in a settings.xml that sets different properties depending on if this is a dev or production build. see: http://maven.apache.org/guides/introduction/introduction-to-profiles.html

根据这是构建服务器,开发人员还是生产部署,我设置了不同的属性

I have different properties set depending on if this is the build server, dev or a production deployment

mvn -Denv = dev || mvn -Denv = dev-build || mvn -Denv = production

mvn -Denv=dev || mvn -Denv=dev-build || mvn -Denv=production

maven链接有一个很好的描述.

The maven link has a pretty good description.

这篇关于我应该将Maven项目的应用程序配置文件放在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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