Maven WebApp tomcat7系统属性

时间:2014-05-02 06:20:44

标签: java maven tomcat7 system-properties

我们正在使用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>

2 个答案:

答案 0 :(得分:5)

通常,将系统属性添加到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

答案 1 :(得分:1)

Maven插件中的系统属性仅用于运行tomcat7:run mojo ...以便将系统属性传递给可执行war(jar)时,必须在命令行上执行: java -DsysProp1 = value -DsysProp2 = value -jar exec-war.jar