使用Maven进行多个部署环境(生产/开发) [英] Using Maven for multiple deployment environment (production/development)

查看:153
本文介绍了使用Maven进行多个部署环境(生产/开发)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Maven中有一个Web应用程序,具有默认目录结构.没问题. 默认目录结构具有一些指向我的本地主机数据库的属性文件.

I have a web app in Maven, with the default directory structure. No problem there. The default directory structure has some property files that point to my localhost database.

当前,我创建一个Ant脚本来创建不同的war文件- 使用以下命令,一个用于生产,一个用于开发:

Currently I create an Ant script to create different war files - one for production and one for development, using these commands:

ant deploy-dev
ant deploy-prod
ant deploy-sit
ant deploy-uat

因此基本上,他们创建了一个war文件,然后通过插入属性文件来更新war文件

So basically they create a war file and then update the war file by plugging in the properties file

行家中是否有类似的东西(根据配置而产生不同的战争)?

Is there something like that in maven (different war created depending on the configuration)?

如果是的话,我该怎么做?

if so, how do i do that?

我尝试了mvn war,但它只会造成战争

i tried mvn warbut it just creates a war

推荐答案

FYI最佳实践是不必必须针对不同的环境重建工件-因为这不会导致可复制生成,并且其他内容在重建时可能会发生变化. IE.如上所述,使用资源过滤仅在重建项目时有效.

FYI best practice is to not have to rebuild your artifact for different environments - as that does not lead to re-produce-able builds, and other things could potentially change when rebuilding. I.e. using resource-filtering, as suggested above, only works when re-building your project.

当您将工件从开发人员毕业到测试或从验收测试到生产的时候,您- 不需要重建.

When you graduate an artifact from dev to test or acceptance test to production - you do not want to have to rebuild.

您要做的实际上是使配置动态化,具体取决于运行时变量. IE.针对不同环境的不同弹簧设置或属性文件,例如:

What you want to do, is actually have your configuration dynamic, dependent on run-time variables. I.e. different spring setups or properties files for different environments e.g:

db-dev.properties
db-test.properties
db-prod.properties

然后,您可以使用运行时变量和Spring的

Then you can switch between these configurations using run-time variables and Spring's PropertyPlaceholderConfigurer.

实际上,您也可以像过去一样使用不同的spring配置文件来进行更复杂的设置.

You can also actually use different spring configuration files as well, as I've done in the past, for more complex setups.

我还建议您将默认"设置保留为生产环境-这样,如果您将其部署到生产环境中,则不必担心是否忘记设置环境变量.

I also suggest you leave your 'default' setup as production - so that if you deploy to production, you don't need to worry if you forget to set the environment variable.

这篇关于使用Maven进行多个部署环境(生产/开发)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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