I am writing an application that requires me to download a jar given the mavens groupid/artifactid/version.
I currently start with
public Model pomToModel(String pomUrl) throws Exception {
URL url = new URL(pomUrl);
InputStream stream = url.openStream();
try {
Model model = new MavenXpp3Reader().read(stream);
return model;
} finally {
stream.close();
}
}
So given the url of the POM, I now have the maven Model object representing it. This seems to work well.
What I would like to do know is two things:
- find the url of the jar artifact that the model represents in the maven repository that the maven plugin would use
- given the model, find the file representing the jar in the local repository
I already have poor quality solutions: I go to mvnrepository.com manually coding the url, and I use ~/.m2/repository as the prefix for the file. I can obviously improve this solution, but I will end up poorly duplicating the code that is well tested and well used in the maven code base.
I'd really like to know how to do this using the maven classes.
I have done a fair bit of google searching, but the amusing thing about searching for anything about maven and jars (even on stackoverflow) is that I find lots of solutions about how to use maven, rather than how to code using the maven classes.
Thanks for the help