Ich arbeite in einem Maven-Web-Projekt durch Eclipse. In der web.xml
habe ich einen Kontext-Parameter, dessen Wert sollte sich ändern, das Profil, das ich verwende, wenn ich den Maven ausführen.Maven: wie man eine Variable in web.xml-Datei füllt
<context-param>
<param-name>producao</param-name>
<param-value>${ambiente.producao}</param-value>
</context-param>
In der pom-Datei für Projekt, das ich die folgende Konfiguration haben:
<project>
<profiles>
<profile>
<id>prod</id>
<properties>
<ambiente.producao>true</ambiente.producao>
</properties>
</profile>
<profile>
<id>desenv</id>
<properties>
<ambiente.producao>false</ambiente.producao>
</properties>
</profile>
</profiles>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/webapp/WEB-INF/</directory>
<filtering>true</filtering>
<includes>
<include>**/web.xml</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.5</version>
<configuration>
<webResources>
<resource>
<filtering>true</filtering>
<directory>src/main/webapp</directory>
<includes>
<include>**/web.xml</include>
</includes>
</resource>
</webResources>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
I Plugin sowohl resources
Tag als Maven-Krieg-Plugin bin mit den Referenzen nach ich im Internet gefunden. Es hat jedoch nicht wie erwartet funktioniert. In der Eclipse starte ich den Maven mit den Zielen sauber zu installieren und als "Profile" entweder prod oder desenv. Nachdem ich den Maven ausgeführt habe, habe ich beobachtet, dass in web.xml
die ${ambiente.producao}
Eigenschaft nicht ersetzt wird. Daher würde ich gerne wissen, was ich falsch gemacht habe. Sollte ich nur die Filtering Ressource oder das Maven-War-Plugin benutzen?
Danke,
Rafael Afonso
Dies ist ein sehr optimaler und rationaler Ansatz und Erklärung. Vielen Dank! –
Dies war ein magischer Schlüssel: "filteringDeploymentDescriptors> true filteringDeploymentDescriptors>" –