How can I in a jsp page get maven project version number?

后端 未结 11 2244
天命终不由人
天命终不由人 2020-12-14 16:07

I am working on a java web application, managed by maven2. From time to time, we did some changes, and want to do new releases, of course with new version number. In the hom

11条回答
  •  一个人的身影
    2020-12-14 16:46

    It make a while this post have been created, but I hope it would help. It will get properties generated from Maven :

    <%@ page import="java.util.*"%>
    <%
        java.io.InputStream inputStream = getServletContext().getResourceAsStream("/META-INF/maven/com.filhetallard.fam.ged/famdox/pom.properties");
        Properties mavenProperties= new Properties();
        mavenProperties.load(inputStream );
        String version = (String) mavenProperties.get("version");
        String name = (String) mavenProperties.get("artifactId");
    
    %>
     
        Application <%= name %> v<%= version %>
    

    Unfortunately, there is some drawbacks :

    • you had to explicitely write groupId and artifactId in your code
    • if you deploy your web-app directly from target/ to your server, it won't find the file because this one is in maven-archiver directory, not in META-INF, before packaging.

    Regards.

提交回复
热议问题