Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to manage project dependencies using Maven?

Tags:

java

linux

maven

This is probably a newbie quesiton, but I'm a newbie when it comes to Java and the Maven documentation is tough to work through and all seems to be written for Maven experts. I'm trying to install a driver in a Java project. I've got a project with code that works (ie, I don't want to torch what I already have) and maven is installed and up-to-date. I know the dependency XML to add to pom.xml, but I don't know where to start to create a pom.xml file.

I tried to run 'mvn install' a couple of times, but I don't see the driver anywhere so I can't reference it with my java build path.

What's the best way to proceed?

like image 260
dudemonkey Avatar asked May 24 '13 13:05

dudemonkey


People also ask

How are dependencies handled in a Maven project?

Transitive Dependencies Discovery Maven does so by reading project files (pom. xml) of dependencies, figure out their dependencies and so on. We only need to define direct dependency in each project pom. Maven handles the rest automatically.

What is Maven dependency management?

What Is Maven Dependency Management? Dependency management in Maven allows teams to manage dependencies for multi-module projects and applications. These can consist of hundreds or even thousands of modules. Using Maven can help teams define, create, and maintain reproducible builds.


1 Answers

First of all check if the maven is installed - mvn --version in the command line.

If not - follow the guide - http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

To create a pom.xml manually is not a good point if you use IDE - just create a new Maven project (for example in Idea or Eclipse). This way you will avoid errors with some required configurational tags missing. Then add the needed dependency in the dependencies tag in pom.xml

Actually, one of the best tutorials about maven is http://www.mkyong.com/tutorials/maven-tutorials/ - there are a lot of topics. Choose the desired one.

If you use Eclipse IDE just follow this tutorial to convert your project to the Maven project - Convert Existing Eclipse Project to Maven Project - and delete the pom.xml created by you before that. Be sure to have the m2eclipse plugin installed in the IDE.

This is for the conversion in the Intellij idea - IntelliJ - Convert a Java project/module into a Maven project/module

like image 136
user Avatar answered Oct 17 '22 01:10

user