Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 951
Ibrahim B. Avatar asked Sep 12 '25 09:09

Ibrahim B.


2 Answers

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.

like image 142
Fritz Duchardt Avatar answered Sep 14 '25 00:09

Fritz Duchardt


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

like image 34
nanite Avatar answered Sep 13 '25 23:09

nanite