Maven Netbeans
NetBeans 6.7 and later versions have Maven built-in. For earlier versions, you can get the Maven plugin from the Plugin Manager. In this example, we use NetBeans 6.9. Some features of NetBeans are as follows:
* You can run Maven goals through NetBeans.
* You can use NetBeans' own console to view the output of Maven commands.
* You can update Maven dependencies with the IDE.
* You can launch Maven builds within NetBeans.
* NetBeans uses Maven's pom.xml to automatically manage dependency relationships.
* NetBeans can resolve Maven dependencies through its own workspace without installing to the local Maven repository, although the dependent projects must be in the same workspace.
* NetBeans can automatically download required dependencies and source code from remote Maven repositories.
* NetBeans provides a wizard for creating Maven projects and pom.xml files.
* NetBeans provides a Maven repository browser that allows you to view local repositories and registered external Maven repositories.
## Open a Maven Project in NetBeans
* Open NetBeans
* Select **File Menu > Open Project** option
* Choose the project path, which is the storage location when creating a project with Maven. Let's assume we created a project: consumerBanking. Check [**Maven Build Java Project**](#) to see how to use Maven to create a project.
!(#)
Now you can see the Maven project in NetBeans. Look at the consumerBanking project's Libraries and Test Libraries. You will find that NetBeans has already added all Maven dependencies to its build path.
!(#)
## Build a Maven Project in NetBeans
Now, let's use NetBeans' compilation feature to build this Maven project
* Right-click on the consumerBanking project to open the context menu.
* Select the "Clean and Build" option
!(#)
Maven will start building the project. You can view the output log information in NetBeans' console:
NetBeans: Executing 'mvn.bat -Dnetbeans.execution=true clean install'NetBeans: JAVA_HOME=C:Program FilesJavajdk1.6.0_21 Scanning for projects...------------------------------------------------------------------------Building consumerBanking task-segment: [clean, install]------------------------------------------------------------------------[clean:clean][resources:resources] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! skip non existing resourceDirectory C:MVNconsumerBankingsrcmainresources [compiler:compile]Compiling 2 source files to C:MVNconsumerBankingtargetclasses [resources:testResources] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! skip non existing resourceDirectory C:MVNconsumerBankingsrctestresources [compiler:testCompile]Compiling 1 source file to C:MVNconsumerBankingtargettest-classes [surefire:test]Surefire report directory: C:MVNconsumerBankingtargetsurefire-reports ------------------------------------------------------- T E S T S -------------------------------------------------------Running com.companyname.bank.AppTestTests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.023 sec Results :Tests run: 1, Failures: 0, Errors: 0, Skipped: 0[jar:jar]Building jar: C:MVNconsumerBankingtargetconsumerBanking-1.0-SNAPSHOT.jar [install:install]Installing C:MVNconsumerBankingtargetconsumerBanking-1.0-SNAPSHOT.jar to C:UsersGB3824.m2repositorycomcompanynamebankconsumerBanking 1.0-SNAPSHOTconsumerBanking-1.0-SNAPSHOT.jar ------------------------------------------------------------------------ BUILD SUCCESSFUL ------------------------------------------------------------------------Total time: 9 seconds Finished at: Thu Jul 19 12:57:28 IST 2012Final Memory: 16M/85M------------------------------------------------------------------------
### Run the Application in NetBeans
Now, right-click on the App.java file. Select the Run File option. You can see the following results in the console:
NetBeans: Executing 'mvn.bat -Dexec.classpathScope=runtime -Dexec.args=-classpath %classpath com.companyname.bank.App -Dexec.executable=C:Program FilesJavajdk1.6.0_21binjava.exe -Dnetbeans.execution=true process-classes org.codehaus.m
YouTip