java - How do I download a jar using maven programatically -
i writing application requires me download jar given mavens groupid/artifactid/version.
i 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; } { stream.close(); } } so given url of pom, have maven model object representing it. seems work well.
what know 2 things:
- find url of jar artifact model represents in maven repository maven plugin use
- given model, find file representing jar in local repository
i have poor quality solutions: go mvnrepository.com manually coding url, , use ~/.m2/repository prefix file. can improve solution, end poorly duplicating code tested , used in maven code base.
i'd know how using maven classes.
i have done fair bit of google searching, amusing thing searching maven , jars (even on stackoverflow) find lots of solutions how use maven, rather how code using maven classes.
thanks help
option 1
aether recommended khmarbaise.
it's native library ships maven 3.0
option 2
if want simple solution downloading maven modules command line or within shell script, apache ivy has standalone jar.
example:
using ivy dependencies manager programmatically
option 3
if you're looking maven jar , don't care dependency management it's simpler.
here's how retrieve log4j jar direct maven central:
curl -o http://search.maven.org/remotecontent?filepath=log4j/log4j/1.2.17/log4j-1.2.17.jar if you're using nexus repository manager has useful rest api
using nexus rest api latest artifact version given groupid/artifactid
Comments
Post a Comment