Making a java project integrate with maven

131 views Asked by At

I am trying to integrate maven with a old style java project to manage dependencies.

To simply download the jars, I could use

mvn dependency:get -DrepoUrl=https://mvnrepository.com -Dartifact=artifactId:groupId:version

But due to some product challenges, I need to add these jars to classPath myself. So if there is some kind of tool/solution to help get these details automatically. Like what all jars got download as part of a specific pom.xml

Example: I could run the above command inside java code with

Runtime.exec()

And parse the output myself, but I was wondering if there is a better way instead of me parsing all that.

Also, please suggest me any better way to deal with such a situation.

PS: I cannot convert the project to Maven project using any tools etc(since I would change the structure of project) rather I have get the similar behavior myself

Update

I found that I could use maven-embedder.jar but I couldn't find much help. I want to use only for downloading the dependency i.e my command to do that would be like below:

mvn test dependency:build-classpath -f "C:\Users\Desktop\My_Pom.xml" -DoutputDirectory="C:\ProgramData\MyDirectoeyRepository"

How could I do this?

2

There are 2 answers

0
user578219 On BEST ANSWER

I ended up using Maven-Embedder's MavenCli class.

5
J Fabian Meier On

I am not sure I understand everything correctly, but using dependency:copy-dependencies (https://maven.apache.org/plugins/maven-dependency-plugin/copy-dependencies-mojo.html) you can download all dependencies of a given pom to a given directory.

This allows you to put them on the classpath of some java project.