Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven filter resources and adding project version

Tags:

maven-2

This is an easy filter approach to write the project version into a file.

<build>
 <resources>
  <resource>
    <directory>src/main/webapp</directory>
    <includes>
      <include>**/*.version</include>
    </includes>
    <filtering>true</filtering>
  </resource>
 </resources>
</build>

This is the project structure (left out the unintresting parts)

├───src
│   └───main
│       ├───java
│       │   └─── [...]
│       └───webapp
│           ├───META-INF
│           └───WEB-INF
│               ├───cfg
│               └───portal.version
└─── pom.xml

The content of portal.version

${project.version}

This should be replaced with the artifact version of the pom.xml, but unfortunately nothing happens. Whats wrong? Thank you in advance

like image 722
Christopher Klewes Avatar asked Sep 23 '10 15:09

Christopher Klewes


People also ask

What is Maven resource filtering?

Resource Filtering. You can use Maven to perform variable replacement on project resources. When resource filtering is activated, Maven will scan resources for property references surrounded by ${ and }.

Where do you put resources in POM?

Via the resources area in the pom you can filter files from their way src/main/resources to the target/classes folder. The lifecycle of Maven is not influenced by this. I have added resources successfully in . Jar file.

What is resources folder in Maven project?

Maven resources folder is used to store all your project resources files like , xml files, images, text files and etc. The default Maven resources folder is located at “yourproject/src/main/resources“.


2 Answers

When you specify resource element, the result filtered content is copied into a target/classes folder. To filter web app resources you could configure maven-war-plugin.

Though to get the version, in most cases it is better to read a standard Maven property file in your application, e.g. META-INF\maven\<groupId>\<artifactId>\pom.properties

like image 172
Eugene Kuleshov Avatar answered Oct 02 '22 18:10

Eugene Kuleshov


To filter web resources, you can use the filtering capabilities of the war plugin.

like image 39
brabster Avatar answered Oct 02 '22 19:10

brabster