maven - 配置文件相关的 web.xml

标签 maven tomcat ssl config

我在我的 tomcat 生产服务器上使用强制 ssl 配置。我想在开发中禁用此功能,并想知道我的选择是什么。配置发生在我的 web.xml 文件中。我目前使用 Maven 构建我的项目,所以我已经有一些配置文件,我更喜欢在其中设置设置。

最佳答案

在您的 web.xml 中的某处,您可能具有以下设置:

<transport-guarantee>CONFIDENTIAL</transport-guarantee>

如果是这样,您可以为传输保证属性使用属性占位符,并在构建期间对其进行资源过滤。将 web.xml 中的那一行替换为:

<transport-guarantee>${transport.guarantee}</transport-guarantee>

您可以为 pom 文件或外部属性文件中的属性 ${transport.guarantee} 分配默认值(可以是“CONFIDENTIAL”),并通过提供命令行参数在开发环境中覆盖它:

mvn clean package -Dtransport.guarantee="NONE"

如果您正在使用 maven war 插件,可以通过以下方式从 pom 文件中启用资源过滤:

      <configuration>
                <webResources>
                    <resource>
                        <filtering>true</filtering>
                        <directory>src/main/webapp</directory>
                        <includes>
                            <include>**/web.xml</include>
                        </includes>
                    </resource>
                </webResources>
                <warSourceDirectory>src/main/webapp</warSourceDirectory>
                <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
            </configuration>

最后,如果您必须使用现有配置文件,则根据激活的配置文件设置 transport.guarantee 的值。一种方法:

<profiles>
 <profile>
  <id>development</id>
  <properties>
    <transport.guarantee>NONE</transport.guarantee>
  </properties>
</profile>
<profile>
  <id>production</id>
  <properties>
    <transport.guarantee>CONFIDENTIAL</transport.guarantee>
  </properties>
</profile>

您希望将生产配置文件设置为默认设置为事件。使用 ~/.m2/settings.xml 文件覆盖并激活您的开发配置文件。

关于maven - 配置文件相关的 web.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18443302/

相关文章:

java - 具有相同凭据的多个 Maven 存储库

java - Spring Mvc学员报名表

c++ - 如何破译 boost asio ssl 错误代码?

amazon-web-services - 在 AWS ELB 实例中终止 SSL

android - 如何将 Robolectric、Maven、ActionBarSherlock(最好是 + IntelliJ)集成到 Android 项目中?

java - Apache 客户端请求配置生成器错误

java - Maven:自动安装外部JAR

java - 如何在 OpenShift 上启动与 JDBC 的连接?

java - 无法加载 Tomcat 服务器配置

oracle - 通过 SSL (PROTOCOL=TCPS) 使用 Oracle 数据库的 Tomcat JDBCRealm