Maven 2:如何在WAR文件中打包当前项目版本? [英] Maven 2: How to package current project version in a WAR file?
问题描述
我正在使用Maven 2来构建我的Java项目,我正在寻找一种方法来向用户呈现pom.xml的当前版本号(例如,使用Servlet或JSP)。
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).
据我所知,最好的方法是Maven将版本号作为文本文件打包到WAR中。这允许我从该文件中读取版本并以我想要的方式呈现它。
As far as I can see, the best way would be that Maven packages the version number as a text file into the WAR. This allows me to read the version from that file and present it the way I want.
有没有人知道一个插件可以为我做这样的事情?也许WAR插件可以这样配置?或者也许一起使用其他方法?
Does anyone know of a plugin that can do something like that for me? Maybe the WAR plugin can be configured to do so? Or maybe using some other approach all together?
推荐答案
您正在寻找资源过滤。甚至在war-plugin创建文件之前就已经完成了。我很确定war-plugin将这个版本打包在web.xml和manifest中,但我不确定如何通过servlet API访问它们,但它也可能是一种有效的方法。
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.
查看 Maven资源插件文档,它会告诉你它是如何完成的。我认为您应该能够使用 $ {version}
替换版本。虽然没有工作的maven安装在这里进行测试。
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.
这篇关于Maven 2:如何在WAR文件中打包当前项目版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!