【问题标题】:Maven WebApp tomcat7 system propertiesMaven WebApp tomcat7 系统属性
【发布时间】:2014-05-02 06:20:44
【问题描述】:

我们正在使用 maven 依赖项在我们的 web 应用程序中添加嵌入式 tomcat。它工作正常,但我需要将 systemProperties 添加到嵌入式 tomcat,以便我们的 webapp 可以使用这个 systemProperties。

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>tomcat-run</id>
                    <goals>
                        <goal>exec-war-only</goal>
                    </goals>
                    <phase>package</phase>
                    <configuration>
                        <path>/html5</path>
                        <enableNaming>true</enableNaming>
                        <finalName>html5.jar</finalName>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

我尝试添加这样的系统属性,但没有成功。我加了

<build>
    <plugins>
        <plugin>
            <configuration>
                <systemProperties>
                    <dashboard.oracle.host>1.1.1.1</dashboard.oracle.host>
                    <dashboard.oracle.port>1521</dashboard.oracle.port>
                    <dashboard.oracle.sid>orcl</dashboard.oracle.sid>
                    <dashboard.oracle.url>
                        jdbc:oracle:thin:@${dashboard.oracle.host}:${dashboard.oracle.port}:${dashboard.oracle.sid}
                    </dashboard.oracle.url>
                    <dashboard.oracle.username>username</dashboard.oracle.username>
                    <dashboard.oracle.password>password</dashboard.oracle.password>
                </systemProperties>
            </configuration>
            ...
        </plugin>
    </plugins>
</build>

【问题讨论】:

    标签: java maven tomcat7 system-properties


    【解决方案1】:

    一般而言,您将系统属性添加到 tomcat 插件的方式是正确的:

    <plugin>
      <groupId>org.apache.tomcat.maven</groupId>
      <artifactId>tomcat6-maven-plugin</artifactId>
      <version>2.1</version>
      <configuration>
        <systemProperties>
          <example.value.1>alpha</example.value.1>
          <example.value.2>beta</example.value.2>
        </systemProperties>
      </configuration>
    </plugin>
    

    取自Apache Docu

    【讨论】:

    • 有没有办法从单独的文件中检索这些属性?在给出的示例中,开发人员可能不希望将用户名和密码放在源代码管理中。
    【解决方案2】:

    Maven 插件中的系统属性仅适用于运行 tomcat7:run mojo ... 为了将系统属性传递给可执行的 war (jar),您必须在命令行中执行此操作: java -DsysProp1=value -DsysProp2=value -jar exec-war.jar

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-14
      • 2015-06-02
      • 2017-11-04
      • 2015-03-18
      • 2012-05-23
      • 2020-08-05
      相关资源
      最近更新 更多