How to show the project version on the JSP page of a Spring MVC Web application

Asked

Viewed 118 times

-1

In the Java Web project with Spring MVC framework has the file pom.xml and within this file has several properties, among these properties has the version of the project: <version>0.0.1-SNAPSHOT</version>

This version of the project is inside the file pom.xml sort of like this

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>

    <groupId>br.com.meuprojetojavaweb</groupId>
    <artifactId>MeuProjeto</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>MeuProjeto</name>

    ...
</project>

And I need to show this version of the project directly on a web page .JSP, preferably in the footer of all pages. Cool as in the code below:

index.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="${pageContext.request.contextPath}/lib/bootstrap/css/bootstrap.min.css">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Hello World!</h1>

    <footer class="main-footer">
        <div class="pull-right hidden-xs">
            <b>Version</b> {project.version}
        </div>
        <strong>Copyright © 2017 <a href="#">MeuProjeto</a>.</strong> Todos os direitos reservados.
    </footer>
    </body>

Where is the "code" {project.version} would be where it fetches the version of the project that is registered in the file pom.xml.

So I ask for help here, because I do not know how to proceed and show the version of my project.

1 answer

1

In the archive pom.xml, add the following setting:

<build>
    <resources>
        <resource>
            <filtering>true</filtering>
            <directory>src/main/resources</directory>
            <includes>
                <include>sistema.properties</include>
            </includes>
        </resource>
    </resources>
</build>

Create a property file in the src/main/Resources directory For example: sistema.properties

inserir a descrição da imagem aqui

Every time you run the Maven task, the file will be updated.

You can access the properties file values anywhere on the system, including a JSP.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.