Maven 2: How to package current project version in a WAR file?

后端 未结 5 1651
[愿得一人]
[愿得一人] 2021-02-06 10:14

I am using Maven 2 to build my Java project and I am looking for a way to present the current version number of the pom.xml to the user (using a Servlet or JSP for example).

5条回答
  •  梦毁少年i
    2021-02-06 10:25

    You're looking to do filtering of resources. This is done even before the war-plugin creates the file. I'm pretty sure the war-plugin packs the version in the web.xml and manifest, but I'm not sure how to access those through servlet APIs, but it might also be a valid approach.

    Have a look at the Maven resource plugin documentation, it'll tell you how it's done. I think you should be able to just substitue the version using ${version}. Haven't got a working maven installation to test it here though.

提交回复
热议问题