DEV Community

Kamil
Kamil

Posted on • Edited on • Originally published at banach.net.pl

2 1

How to put pom.xml version and build date in properties?

While working on webapp API in Java I need to send the app version and the build date to the frontend. But how to make this?

As my API build is based on maven I thought about getting version from pom.xml file. So, let's make it this way!

Solution! Almost...

I need to put in the pom.xml file configuration responsible for resources filtering:

<build>
 <!-- clipped -->
   <resources>
     <resource>
       <directory>src/main/resources</directory>
       <filtering>true</filtering>
     </resource>
   </resources>
</build>
Enter fullscreen mode Exit fullscreen mode

And in the app.properties properties which will be replaced during build:

build.version=${pom.version}
build.date=${timestamp}
Enter fullscreen mode Exit fullscreen mode

After the build my app.properties is filled with expected data:

image

Now I can access version from POM and last build in Java app easily!

And fin^H^H... another problem?

Everything works smoothly, I can get the version from the pom.xml and also the build date. But... a favicon is now broken! What?!

Frontend is deployed along with backend (using Javalin static files feature and files were loaded from resources folder.

It turns out that the resource filtering plugin processe favicon.ico (in fact all .ico files) and broke them by saving them incorrectly. So I need to exclude those files from filtering!

Final solution

Final configuration in the pom.xml looks like in snippet below.

It processing all files in src/main/resources except all .ico files. But I want .ico in resource folder - so I need add them but without filtering (processing them).

<build>
 <!-- clipped -->
   <resources>
     <resource>
       <directory>src/main/resources</directory>
       <filtering>true</filtering>
       <excludes>
         <exclude>**/*.ico</exclude>
       </excludes>
     </resource>
     <resource>
       <directory>src/main/resources</directory>
       <filtering>false</filtering>
       <includes>
         <include>**/*.ico</include>
       </includes>
     </resource>
   </resources>
</build>
Enter fullscreen mode Exit fullscreen mode

And that's all - everything is now OK ;-)

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs