Search

Dark theme | Light theme

July 2, 2009

Add Maven dependency in NetBeans

Maven support has improved a lot in NetBeans 6.7. One of the small, but important, features is the possibility to add a new dependency to a Maven project. In the previous version of NetBeans we could add a new library, but then we had to know the artifact and group name ourselves. In NetBeans 6.7 we can search for dependencies in the repositories, add an opened project or use the dependency management features of Maven.

To add a new dependency we right-click on the Libraries node of a Maven project and select Add Dependency....

NetBeans opens a dialog window where we can do several things to a dependency to our project. We can fill in the input fields ourselves and choose the scope from the Scope combobox.

But we can also search for a dependency in the repositories. To do this we must type text in the Query input field. The Search Results shows found libraries as we type. We select the library we want and press the OK button to add it to our project.

Instead of using a query we can use the Dependency Management tab. This tab is enabled if our project's POM contains a dependencyManagement section (or the parent POM most likely). The tab shows all available artifacts that are defined in the dependencyManagement. We select the artifact we want to add to our project and press the OK button to add it to our POM.

And finally we can even select the artifact from one of the open Maven projects in NetBeans. If we have more than one Maven project in the Projects window the Open Projects tab of the Add Dependency dialog window is enabled. To add the project's artifact to our POM we select the project and press the OK button.