简体   繁体   中英

Java - access pom.xml file from JAR

I'm working on a plugin capable of displaying the list of the dependencies of a Maven project. To make this possible, I read the pom.xml file and print data on the console for debugging. This worked just fine, until I tried it from the JAR file : I got a FileNotFoundException (for the pom.xml file)

  • Is there a better way to list dependencies of a Maven project ?
  • How to read pom.xml when we are inside the JAR file ?

Here is my original question

As suggested JF Meier , I tried to read the pom.xml file as a resource and it worked.

MyClass obj = new MyClass();
InputStream pomFile = obj.getClass().getClassLoader().getResourceAsStream("META-INF/maven/groupId/artifactId/pom.xml");

The only issue now is that the path to the file will not be the same for each project as it depends of the groupId and the artifactId

What worked for me was

$ unzip foo.jar foo
$ cat foo/META-INF/maven/com.bar/foo/pom.xml

Another idea that didn't work for me instead of unzip ping is jar -xf foo.jar

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM