单独的web.xml用于开发和生产 [英] Separate web.xml for development and production

查看:125
本文介绍了单独的web.xml用于开发和生产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的web.xml在开发环境和生产环境中是不同的。例如在开发环境中,不需要安全限制。



通常我部署新的应用程序版本如下:



< $ / $>
  • 将Eclipse项目导出到WAR。

  • 将WAR上传到服务器。

  • 重新部署。 b $ b

    问题是我必须在导出之前手动取消web.xml中的安全约束。



    你如何解决这个问题?



    我还在一些文章中认为web.xml很少更改。但是如果web.xml在每次更新时导出为WAR,那么web.xml如何才能更改?



    提前感谢!

    解决方案

    如果在开发过程中不能使用相同的 web.xml ,我将自动化构建过程,使用两个 web.xml ,并根据Brian建议的目标环境在构建时捆绑正确。但是,而不是Ant,我会选择Maven,因为它将需要更少的工作IMHO,它有一个内置的功能,称为个人资料,这是完美的管理环境特定的东西,如这里。换句话说,我会将构建放在Maven 2下,并使用包含特定maven-war-plugin配置的生产配置文件构建包含具有所需安全限制的 web.xml 的WAR。另一个选择是合并开发 web.xml 货物可以做到这一点)来增加安全约束,但这已经是一个更先进的解决方案(要复杂一点)。


    My web.xml is different in devel and production environments. For example in development environment there is no need in security constraints.

    Typically I deploy new application version as follows:

    1. Export Eclipse project to WAR.
    2. Upload WAR to the server.
    3. Redeploy.

    The problem is that I have to manually uncomment security constraints in web.xml before exporting.

    How do you solve this problem?

    I also met an opinion in some articles that "web.xml is rarely changed". But how can web.xml not change if it is exported to WAR on every update?

    Thanks in advance!

    解决方案

    If you can't use the same web.xml during development, I would automate the build process, use two web.xml and bundle the "right" one at build time depending on the targeted environment as Brian suggested. But, instead of Ant, I'd choose Maven because it will require less work IMHO and it has a built-in feature called profiles that is perfect to manage environment specific stuff like here.

    In other words, I'd put the build under Maven 2 and use a production profile containing a specific maven-war-plugin configuration to build a WAR containing a web.xml having the required security constraints. Another option would be to merge the development web.xml (cargo can do that) to add the security-constraints but this is already a bit more "advanced" solution (a bit more complex to put in place).

    这篇关于单独的web.xml用于开发和生产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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