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.


2 comments:
Nice post. Tried and works! :-) Obviously...
One question: what if the project I need is not present in the Maven repository? In one situation I was able to create a new local Maven for such project and rebuild it and use if as reference but obviously it's not the "official" release.
Also, what if I only have the JAr? I.e.: the JLFGR 1.0 (Java Look and Feel Graphics Repository). Any suggestion?
Many thanks.
@Marco:
Project placed in your local repository are just as valid. It doesn't matter if it is an official release or not. So a SNAPSHOT release can be used as a dependency. Running mvn install on a project will place it in your local Maven repository and NetBeans can access it without problems.
If you only have a JAR file you must add it to your local Maven repository with the mvn install:install-file command. See the Maven FAQ for more info.
Post a Comment