在Eclipse WTP中的web.xml servlet-mapping中使用Maven $ {project.version}

时间:2017-11-22 15:13:50

标签: java maven tomcat eclipse-wtp maven-war-plugin

编辑澄清我要求使用Tomcat的Eclipse WTP解决方案。

我已经通过使用 web.xml 中的变量${project.version}和maven-war-plugin过滤来实现 for WAR artifacts 如下。

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

我想在Eclipse WTP运行的Tomcat 中使用 web.xml ${project.version}的值,如下所示。

<servlet-mapping>
    <servlet-name>jersey</servlet-name>
    <url-pattern>/api/${version}/*</url-pattern>
</servlet-mapping>

我尝试过滤如下,但这不起作用,我仍然得到 404 。我知道过滤机制通常应用于访问源代码中的Maven变量而不是web.xml,但我虽然这也适用于我的情况......

POM摘录

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

<servlet-mapping>
    <servlet-name>jersey</servlet-name>
    <url-pattern>/api/v${version}/*</url-pattern>
</servlet-mapping>

我知道这个机制用于获取Java源代码中的属性(例如https://stackoverflow.com/a/15356374/731040https://developer.jboss.org/wiki/HowToConfigureJavaEEApplicationToApplyDifferentSettingsinWebxmlEtcForVariousEnvironmentsByMaven),但是认为这可能对于变量是开箱即用的注入到web.xml中也是如此。唉,它没有

0 个答案:

没有答案