Reputation: 578
I have a maven project with several dependencies that are developed internally by my team. I need some information contained on the MANIFEST.mf files of those dependencies at build time of my current project.
Just to be clear. I don't want to get information from my own MANIFEST.mf file (the one from the project I am building). I want to access information contained inside the MANIFEST.mf files of the dependencies of my project at build time.
I built a maven plugin where I can check the dependency tree and retrieve some basic information about the dependencies, however I haven't found a straight forward way of getting to the MANIFEST.mf files.
Do you have any clues on how I can access them (programatically)?
Thanks!
Upvotes: 1
Views: 1641
Reputation: 5872
Maybe something like this would work for you
public void readManifests() throws IOException {
URLClassLoader classLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
for(URL url: classLoader.getURLs()) {
Manifest manifest = new JarFile(url.getFile()).getManifest();
}
}
Upvotes: 0
Reputation: 12345
Use the file of the artifact to create a https://docs.oracle.com/javase/8/docs/api/java/util/jar/JarFile.html , which gives you access to the Manifest
Upvotes: 1