- Maven - Discussion
- Maven - Useful Resources
- Maven - Quick Guide
- Maven - Questions and Answers
- Maven - IntelliJ IDEA
- Maven - NetBeans
- Maven - Eclipse IDE
- Maven - Web Application
- Maven - Deployment Automation
- Maven - Manage Dependencies
- Maven - Build Automation
- Maven - Snapshots
- Maven - Project Templates
- Maven - Project Documents
- Maven - External Dependencies
- Maven - Build & Test Project
- Maven - Creating Project
- Maven - Plug-ins
- Maven - Repositories
- Maven - Build Profiles
- Maven - Build Life Cycle
- Maven - POM
- Maven - Environment Setup
- Maven - Overview
- Maven - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Maven - NetBeans
NetBeans 6.7 and newer has in-built support for Maven. In case of previous version, Maven plugin is available in plugin Manager. We are using NetBeans 6.9 in this example.
Some of features of NetBeans are psted below −
You can run Maven goals from NetBeans.
You can view the output of Maven commands inside the NetBeans using its own console.
You can update maven dependencies with IDE.
You can Launch Maven builds from within NetBeans.
NetBeans does the dependency management automatically based on Maven s pom.xml.
NetBeans resolves Maven dependencies from its workspace without instalpng to local Maven repository (requires dependency project be in same workspace).
NetBeans automatic downloads required dependencies and sources from the remote Maven repositories.
NetBeans provides wizards for creating new Maven projects, pom.xml.
NetBeans provides a Maven Repository browser that enables you to view your local repository and registered external Maven repositories.
Following example will help you to leverage benefits of integrating NetBeans and Maven.
Open a maven project in NetBeans
Open NetBeans.
Select File Menu > Open Project option.
Select Project location, where a project was created using Maven. We ve created a Java Project consumerBanking. Go to ‘Creating Java Project’ chapter, to see how to create a project using Maven.
Now, you can see the maven project in NetBeans. Have a look at consumerBanking project Libraries and Test Libraries. You can see that NetBeans has added Maven dependencies to its build path.
Build a maven project in NetBeans
Now, Its time to build this project using maven capabipty of NetBeans.
Right Cpck on consumerBanking project to open context menu.
Select Clean and Build as option.
Maven will start building the project. You can see the output in NetBeans Console as follows −
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] [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! skip non existing resourceDirectory C:MVNconsumerBankingsrcmain esources [compiler:compile] Compipng 2 source files to C:MVNconsumerBanking argetclasses [resources:testResources] [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! skip non existing resourceDirectory C:MVNconsumerBankingsrc est esources [compiler:testCompile] Compipng 1 source file to C:MVNconsumerBanking arget est-classes [surefire:test] Surefire report directory: C:MVNconsumerBanking argetsurefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.companyname.bank.AppTest Tests 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:MVNconsumerBanking argetconsumerBanking-1.0-SNAPSHOT.jar [install:install] Instalpng C:MVNconsumerBanking argetconsumerBanking-1.0-SNAPSHOT.jar to C:UsersGB3824.m2 epositorycomcompanynameankconsumerBanking 1.0-SNAPSHOTconsumerBanking-1.0-SNAPSHOT.jar ------------------------------------------------------------------------ BUILD SUCCESSFUL ------------------------------------------------------------------------ Total time: 9 seconds Finished at: Thu Jul 19 12:57:28 IST 2012 Final Memory: 16M/85M ------------------------------------------------------------------------
Run Apppcation in NetBeans
Now, right cpck on App.java. Select Run File as option. You will see the result in the NetBeans Console.
NetBeans: Executing mvn.bat -Dexec.classpathScope = runtime -Dexec.args = -classpath %classpath com.companyname.bank.App -Dexec.executable = C:Program FilesJavajdk1.6.0_21injava.exe -Dnetbeans.execution = true process-classes org.codehaus.mojo:exec-maven-plugin:1.1.1:exec NetBeans: JAVA_HOME = C:Program FilesJavajdk1.6.0_21 Scanning for projects... ------------------------------------------------------------------------ Building consumerBanking task-segment: [process-classes, org.codehaus.mojo:exec-maven-plugin:1.1.1:exec] ------------------------------------------------------------------------ [resources:resources] [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! skip non existing resourceDirectory C:MVNconsumerBankingsrcmain esources [compiler:compile] Nothing to compile - all classes are up to date [exec:exec] Hello World! ------------------------------------------------------------------------ BUILD SUCCESSFUL ------------------------------------------------------------------------ Total time: 1 second Finished at: Thu Jul 19 14:18:13 IST 2012 Final Memory: 7M/64M ------------------------------------------------------------------------Advertisements