NetBeans 6.7和更新版本对Maven具有内置支持。在以前的版本中,Maven插件在插件管理器中可用。在这个例子中我们使用的是NetBeans 6.9。
下面列出了NetBeans的一些功能
您可以从NetBeans运行Maven目标。
您可以使用自己的控制台查看NetBeans内的Maven命令的输出。
您可以使用IDE更新maven依赖关系。
您可以从NetBeans中启动Maven创建。
NetBeans根据Maven的pom.xml自动执行依赖关系管理。
NetBeans从其工作空间解析Maven依赖关系,而无需安装到本地Maven存储库(需要依赖项目位于同一工作区中)。
NetBeans自动下载需要远程Maven存储库的依赖关系和源。
NetBeans提供了创建新的Maven项目pom.xml的向导
NetBeans提供了一个Maven Repository浏览器,使您可以查看本地存储库和注册的外部Maven存储库。
以下示例将帮助您充分利用集成NetBeans和Maven的优势。
打开NetBeans
选择文件菜单>打开项目 选项。
选择项目位置,使用Maven创建一个项目。我们创建了一个Java Project consumerBanking.See Maven创建项目,以了解如何使用Maven创建一个项目。
现在,您可以在NetBeans中看到maven项目。查看consumerBanking项目库和测试库。您可以看到NetBeans已将Maven依赖项添加到其创建路径。
现在,它使用NetBeans的maven功能创建此项目。
右键单击consumerBanking项目以打开上下文菜单。
选择清洁和创建作为选项
Maven将开始建设项目。您可以在NetBeans控制台中看到输出
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] Compiling 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] Compiling 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] Installing 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 ------------------------------------------------------------------------
现在,右键单击App.java。选择运行文件为选项。您将在NetBeans控制台中看到结果。
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 ------------------------------------------------------------------------