Edited to clarify that I'm asking for a solution for Eclipse WTP with Tomcat.
I have since got this to work for WAR artifacts by just using the variable ${project.version}
in web.xml in conjunction with maven-war-plugin filtering as follows.
<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>
</edit>
I'd like to use the value of ${project.version}
in web.xml in an Eclipse WTP-run Tomcat as follows.
<servlet-mapping>
<servlet-name>jersey</servlet-name>
<url-pattern>/api/${version}/*</url-pattern>
</servlet-mapping>
I've tried filtering as follows, but this doesn't work, I still get a 404. I know that the filtering mechanism is usually applied to access Maven variables in the source code rather than web.xml, but I though this might work for my case too...
POM excerpt
<build>
<filters>
<filter>${basedir}/src/main/filters/${filter.name}.properties</filter>
</filters>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<webResources>
<resource>
<directory>${basedir}/src/main/webapp</directory>
<filtering>true</filtering>
<includes>
<include>WEB-INF/web.xml</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
...
<properties>
<filter.name>version</filter.name>
</properties>
/src/main/filters/version.properties
version=${project.version}
web.xml excerpt
<servlet-mapping>
<servlet-name>jersey</servlet-name>
<url-pattern>/api/v${version}/*</url-pattern>
</servlet-mapping>
I know that this mechanism is meant to be used for getting properties in the Java source (e.g., https://stackoverflow.com/a/15356374/731040, https://developer.jboss.org/wiki/HowToConfigureJavaEEApplicationToApplyDifferentSettingsinWebxmlEtcForVariousEnvironmentsByMaven), but thought this might work out-of-the-box for variable injection into web.xml as well. Alas, it doesn't