3

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

2 回答 2

6

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

于 2015-03-26T10:23:59.383 回答
2

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

于 2015-06-18T15:58:07.617 回答