Maven: how to fill a variable in web.xml file

梦想与她 提交于 2019-11-28 07:51:39
Fred Bricon

Don't believe everything you read on the Internet. You should remove src/main/webapp/WEB-INF/ from the resources list, it will just filter your web.xml to target/classes

Your maven-war-plugin configuration just needs :

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <version>2.5</version>
  <configuration>
    <filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
  </configuration>
</plugin>

Now, whether you build in Maven CLI or within Eclipse, you need to enable one of these profiles. In command line, you need to run

mvn clean package -Pdesenv

In Eclipse (assuming you're using the Luna Java EE distribution or more recent), you can enable the profile you want by pressing Ctrl+Alt+P. If you enable desenv, you'll see the filtered web.xml under target/m2e-wtp/web-resources/WEB-INF/ This is the file that will get published to your application server.

If you happen to enable both profiles at the same time, the latest profile listed in your pom.xml takes precedence.

Personally, I would remove the production profile and put the production properties in the default properties section of your pom.xml. That way, you always filter your web.xml with actual values and you'll have less chances of accidentally building and deploying your app with non-production settings.

And in order to enable the desenv profile automatically in Eclipse, you can add the following activation rule :

<profile>
  <id>desenv</id>
  <!-- This profile is only activated when building in Eclipse with m2e -->
  <activation>
    <property>
      <name>m2e.version</name>
    </property>
  </activation>
  <properties>
    <ambiente.producao>false</ambiente.producao>
  </properties>
</profile>

More on dynamic resource filtering support in m2e-wtp here: https://developer.jboss.org/en/tools/blog/2011/05/03/m2eclipse-wtp-0120-new-noteworthy

And a screencast there : http://screencast.com/t/hwodHqODBB

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!