I need to display build number in my index.jsp page
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8" />
<title>Title (build: BUILDNUMBER )
</head>
The build number can be supplied by maven into a *.properties file. What is the best way to read *.properties file and display a property with Spring?
Warning: Resources filtering does not work this way for .jsp files. As Pascal Thivent pointed out (thank you) an index.jsp is not a resource but belongs to the webapp.
I do not know the exact answer to your question but you could hard-code the buildnumber into the index.jsp file with maven directly when the index.jsp file is copied to the target directory. You only would need to insert a variable into the index.jsp and configure the maven-resource-plugin to enable filtering.
Example:
index.jsp
Maven Configuration (extract from pom.xml)
For more information on filtering have a look at the Maven Filtering Manual
Here's how I've done it, using maven + jstl and leaving out Spring as it just makes it more complicated.
build.jsp
Maven pom
More details about the usage of buildnumber-maven-plugin can be found on the usage page.
You may load the
.properties
file as a localization message source (usingResourceBundlerMessageSource
) and access it in JSP using<spring:message>
or<fmt:message>
:src/main/resources/buildInfo.properties
:where
buildNumber
is exposed as Roland Schneider suggests.Context configuration:
JSP file:
pom.xml
: