Ibrahim B.
Ibrahim B.

Reputation: 83

Maven WebApp tomcat7 system properties

We are using a maven dependency to add embedded tomcat on our webapplication. It works fine, but I need to add systemProperties to embedded tomcat, so that our webapp can use this 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>

I tried to add system properties like this, but it didn't work. I added it

<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>

Upvotes: 4

Views: 5886

Answers (2)

nanite
nanite

Reputation: 67

the system properties in the Maven Plugin are only for when running the tomcat7:run mojo ... in order to pass in the system properties to the executable war (jar), you must do it on the command line: java -DsysProp1=value -DsysProp2=value -jar exec-war.jar

Upvotes: 2

Fritz Duchardt
Fritz Duchardt

Reputation: 11920

In general the way you have added the system properties to the tomcat plugin is correct:

<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>

Taken from the Apache Docu.

Upvotes: 7

Related Questions