Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a build timestamp in a Java web application using Maven?

I want to show the build timestamp on my website using Wildfly 9. I created a buildInfo.properties with build.timestamp=${timestamp}.

pom.xml:

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.daksa.consolidated.statement</groupId>
        <artifactId>consolidated-statement</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <artifactId>consolidated-statement-war</artifactId>
    <packaging>war</packaging>
    <name>consolidated-statement-war</name>
    <description>consolidated-statement-war</description>


<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.target>1.7</maven.compiler.target>
    <maven.compiler.source>1.7</maven.compiler.source>
    <timestamp>${maven.build.timestamp}</timestamp>
</properties>

<dependencies>
    <!-- Daksa -->
    <dependency>
        <groupId>com.daksa.sandra</groupId>
        <artifactId>sandra-api</artifactId>
        <version>2.0-SNAPSHOT</version>
    </dependency>

    <!-- Java EE -->
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>7.0</version>
        <scope>provided</scope>
    </dependency>

    <!-- Logging -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.12</version>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.1.1</version>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-core</artifactId>
        <version>1.1.1</version>
    </dependency>

    <!-- Testing -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-all</artifactId>
        <version>1.9.5</version>
        <scope>test</scope>
    </dependency>

    <!-- Primefaces -->
    <dependency>
        <groupId>org.primefaces</groupId>
        <artifactId>primefaces</artifactId>
        <version>5.3</version>
    </dependency>
    <dependency>
        <groupId>org.primefaces.extensions</groupId>
        <artifactId>primefaces-extensions</artifactId>
        <version>3.0.0</version>
    </dependency>

    <!-- Shiro -->
    <dependency>
        <groupId>org.apache.shiro</groupId>
        <artifactId>shiro-core</artifactId>
        <version>1.2.3</version>
    </dependency>
    <dependency>
        <groupId>org.apache.shiro</groupId>
        <artifactId>shiro-web</artifactId>
        <version>1.2.3</version>
    </dependency>

    <!-- POI -->
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.13</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.13</version>
    </dependency>

    <!-- CSV -->
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-csv</artifactId>
        <version>1.2</version>
    </dependency>

    <!-- JSON -->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.6.3</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.6.3</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.6.3</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.module</groupId>
        <artifactId>jackson-module-jaxb-annotations</artifactId>
        <version>2.6.3</version>
    </dependency>

    <!-- Guava -->
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>18.0</version>
    </dependency>

    <!-- Atmosphere -->
    <dependency>
        <groupId>org.atmosphere</groupId>
        <artifactId>atmosphere-runtime</artifactId>
        <version>2.4.1</version>
    </dependency>

    <!-- Apache Commons Code  -->
    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <version>1.10</version>
    </dependency>

    <!-- Ehcache -->
    <dependency>
        <groupId>net.sf.ehcache</groupId>
        <artifactId>ehcache</artifactId>
        <version>2.10.1</version>
    </dependency>   

            <!-- Jasper Report -->
            <dependency>
                    <groupId>net.sf.jasperreports</groupId>
                    <artifactId>jasperreports</artifactId>
                    <version>6.2.0</version>
                    <type>jar</type>
                    <exclusions>
                        <exclusion>
                            <artifactId>javassist</artifactId>
                            <groupId>jboss</groupId>
                        </exclusion>
                    </exclusions>
            </dependency>
            <dependency>
                    <groupId>org.codehaus.groovy</groupId>
                    <artifactId>groovy-all</artifactId>
                    <version>2.4.5</version>
                    <exclusions>
                        <exclusion>
                            <artifactId>javassist</artifactId>
                            <groupId>jboss</groupId>
                        </exclusion>
                    </exclusions>
            </dependency>

    <!-- Common -->
    <dependency>
        <groupId>commons-net</groupId>
        <artifactId>commons-net</artifactId>
        <version>3.4</version>
        <type>jar</type>
    </dependency>                                               
</dependencies>

<profiles>
    <profile>
        <id>default</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.16</version>
                    <configuration>
                                                <skip>true</skip>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>
    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>            
    </build>
<repositories>

</repositories>

When I run the program, there is an error:

"{\"WFLYCTL0080: Failed services\" => {\"jboss.persistenceunit.\\"consolidated-statement-war-1.0-SNAPSHOT.war#consolidatedStatement\\".FIRST_PHASE\" => \"org.jboss.msc.service.StartException in service jboss.persistenceunit.\\"consolidated-statement-war-1.0-SNAPSHOT.war#consolidatedStatement\\".FIRST_PHASE: org.hibernate.jpa.boot.archive.spi.ArchiveException: Could not build ClassFile Caused by: org.hibernate.jpa.boot.archive.spi.ArchiveException: Could not build ClassFile\"}}"

But if I remove the build section in my pom.xml, the application runs but the timestamp does not show. How do I get the timestamp to display?

like image 579
berry Avatar asked Sep 25 '22 19:09

berry


1 Answers

It seems problem happens when you apply filtering on whole src/main/resources folder.

Try to limit filtering only to buildInfo.properties as described in http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html

<build>
...
<resources>
  <resource>
    <directory>src/main/resources</directory>
    <filtering>true</filtering>
    <includes>
      <include>**/buildInfo.properties</include>
    </includes>
  </resource>
  <resource>
    <directory>src/main/resources</directory>
    <filtering>false</filtering>
    <excludes>
      <exclude>**/buildInfo.properties</exclude>
    </excludes>
  </resource>
  ...
</resources>
...

like image 159
michaldo Avatar answered Oct 11 '22 13:10

michaldo