3

I am trying to get application's version and name/artifact-id from server at runtime for the plugin I am developing.
I know I can get the details from pom.properties that is generated on the server, using below code

java.io.InputStream inputStream = getServletContext().getResourceAsStream("/META-INF/maven/<application-directory-structure>/pom.properties");
Properties mavenProperties= new Properties();
mavenProperties.load(inputStream );
String version = (String) mavenProperties.get("version");
String name = (String) mavenProperties.get("artifactId");

But I am not able to reach to the pom.properties.
I tried using JarFile.getEntries()but as I am not able to get the name of the war at runtime, its not working.
Any suggestions how I can get the details I am looking for?
I can't modify the maven plugin to get the artifact details. I am making a plugin myself and can't force all the apps for that.

Sandiip Patil
  • 456
  • 1
  • 4
  • 21
  • 2
    possible duplicate of [How to get Maven Artifact version at runtime?](http://stackoverflow.com/questions/2712970/how-to-get-maven-artifact-version-at-runtime) –  Sep 19 '13 at 09:44
  • Possibly but as it says one needs to modify the config in order to write the details. Also I am trying to find from war and it gives from Jar. correct me if I am wrong. – Sandiip Patil Sep 19 '13 at 11:19
  • @SandiipPatil AFAIC a WAR has the same internal format as a JAR, it just has a different file extension. As said [here](http://maven.apache.org/guides/mini/guide-archive-configuration.html) the config should also work with WARs. – cr7pt0gr4ph7 Apr 20 '14 at 22:51

2 Answers2

0

maybe this link could help you: http://technotes.tostaky.biz/2012/08/understanding-absolute-and-relative.html

ps: Understanding Absolute and Relative Path with getResourceAsStream()

java_newbie
  • 821
  • 1
  • 13
  • 24
0

A little late maybe, but for the record: I got something like this to work by:

-NOT prefixing a leading slash ("/"), and -using Thread.currentThread().getContextClassLoader().getResourceAsStream(...) and -use the maven groupId and artifactId

Example

Thread.currentThread().getContextClassLoader().getResourceAsStream("META-INF/maven/org.apache.logging.log4j/log4j-core/pom.properties");

starball
  • 20,030
  • 7
  • 43
  • 238
Guy Pardon
  • 484
  • 2
  • 8