4

I'm trying to debug my Maven webapp project using Eclipse Luna to launch it in Tomcat 8. Unfortunately, the build timestamp is not getting resolved during resource filtering when trying to deploy it to Tomcat. The WAR file built by Eclipse has it resolved, but what it deploys to Tomcat (through the "Run on Server" option) doesn't.

In my pom.xml, I've got:

<properties>
  <timestamp>${maven.build.timestamp}</timestamp>
</properties>

<build>
  <finalName>rapid-installer</finalName>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-war-plugin</artifactId>
      <version>2.4</version>
      <configuration>
        <failOnMissingWebXml>false</failOnMissingWebXml>
      </configuration>
    </plugin>
  </plugins>
  <resources>
    <resource>
      <directory>src/main/resources</directory>
      <filtering>true</filtering>
    </resource>
  </resources>
</build>

And in a properties file, I've got

build.date=${timestamp}
approxiblue
  • 6,982
  • 16
  • 51
  • 59
css
  • 944
  • 1
  • 9
  • 27
  • does it work if you close eclipse and just run the command on the command line? Eclipse often replaces the files maven copies once it detects changes. What often helps is to clean install the project, let eclipse rebuild and do another install so the filtering applies. Maybe it is possible to configure the goal for resource copying so filtering works even if eclipse does the work (I thought I've seen such a feature). – wemu Dec 15 '14 at 13:53
  • Thanks for the reply. If I build the WAR and deploy it to Tomcat manually, the resource filtering works, but if I deploy it from within Eclipse, it doesn't. That might be OK, but I really need to use the debugger at the moment. – css Dec 15 '14 at 14:01
  • If I remember this correctly there is a lifecycle mapping plugin that configures maven plugins to be executed when eclipse is working. It may be this just works today as it seems they have extracted the lifecycle mapping into "lifecycle-mapping-metadata.xml", see https://wiki.eclipse.org/M2E_compatible_maven_plugins - I've seen the lifecycle-mapping plugin configured in pom.xml files too. Not sure where it is documented :/ – wemu Dec 16 '14 at 08:27
  • Possible duplicate of [How to acces maven.build.timestamp for resource filtering](http://stackoverflow.com/questions/13228472/how-to-acces-maven-build-timestamp-for-resource-filtering) – approxiblue Oct 19 '15 at 20:28

2 Answers2

5

The solution for me was to add the following to my pom.xml, so that a timestamp was available, making it so that the app didn't crash in startup in Tomcat.

<profiles>
  <profile>
  <id>m2e</id>
    <activation>
      <property>
        <name>m2e.version</name>
      </property>
    </activation>
    <properties>
      <maven.build.timestamp>2014-01-01</maven.build.timestamp>
    </properties>
  </profile>
</profiles>

Now when the app is deployed to Tomcat through "Run on Server" in Eclipse, it always shows that build timestamp. For details as to why this needs to be done and how it works: https://bugs.eclipse.org/bugs/show_bug.cgi?id=388874

css
  • 944
  • 1
  • 9
  • 27
1

That is normal, unfortunately.

Deploying an application in Tomcat using eclispe WTP mechanism completly bypasses maven lifecycle. This gets even more annoying once you start using war overlays and such "fancy" things offered by maven.

The only solution, so far, is to NOT deploy using the eclipse WTP views, but instead to use the maven cargo plugin.

gizmo
  • 11,819
  • 6
  • 44
  • 61