How to Get Maven Project Version From Java Method as Like at Pom -
i can variable's values pom file i.e.:
${project.version}
and developing custom maven plugin , can set expressions don't want it. how can in java method pom file?
ps: system.getproperty("project.version") doesn't work, should find generic solution because utilize @ other things i.e. getting bamboo build number etc.
i did in web project using maven-war-plugin inject version manifest, getting there java code. see no reason why similar can't done non-web project.
e.g.
<plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-war-plugin</artifactid> version>2.4</version> <configuration> <archive> <manifest> <adddefaultimplementationentries>true</adddefaultimplementationentries> </manifest> </archive> </configuration> </plugin>
then in java (excluding error handling):
public string getmavenversion(servletcontext ctx) { string appserverhome = ctx.getrealpath("/"); file manifestfile = new file(appserverhome, "meta-inf/manifest.mf"); manifest mf = new manifest(); mf.read(new fileinputstream(manifestfile)); attributes atts = mf.getmainattributes(); homecoming atts.getvalue("implementation-build"); }
java maven maven-plugin-development
No comments:
Post a Comment