NetBeans6.7更新版本已經(jīng)內(nèi)置對Maven支持。如遇以前的版本,Maven插件在插件管理器中可用。我們正在使用NetBeans在這個例子中使用6.9。
在NetBeans一些特點如下
您可以從NetBeans運行Maven目標(biāo)。
您可以可以查看Maven命令的輸出使用其自己的控制臺在NetBeans里面??。
你可以更新maven的依賴關(guān)系的IDE。
您可以啟動Maven從內(nèi)部的NetBeans版本。
NetBeans不依賴自動管理基于Maven的pom.xml。
NetBeans解決Maven的依賴關(guān)系從它的工作空間,而不需要安裝到本地Maven倉庫(需要依賴項目在同一個工作區(qū))。
NetBeans自動下載需要的依賴和源從遠程Maven倉庫。
NetBeans提供向?qū)?,用于?chuàng)建新的Maven項目及pom.xml
NetBeans提供一個Maven資源庫瀏覽器,使您可以查看您的本地存儲庫和注冊的外部Maven倉庫。
下面的例子將幫助您充分利用NetBeans的集成和Maven的好處。
打NetBeans.
選擇 File Menu > Open Project 選項.
選擇項目的位置,使用Maven在那里創(chuàng)建了一個項目。我們已經(jīng)創(chuàng)建一個Java項目consumerBanking。看到Maven創(chuàng)建項目,看看如何創(chuàng)建使用Maven項目。
現(xiàn)在,你可以看到Maven項目在NetBeans??纯碿onsumerBanking項目庫和測試庫??梢钥吹?,NetBeans的增加了Maven的依賴關(guān)系到它的構(gòu)建路徑。
現(xiàn)在,它使用NetBeans的Maven來構(gòu)建項目。
右鍵點擊consumerBanking項目打開上下文菜單。
選擇清理并生成可選項
Maven將開始建設(shè)該項目。你可以看到在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:MVNconsumerBankingsrcmainesources [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 estesources [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.m2epositorycomcompanynameankconsumerBanking 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 ------------------------------------------------------------------------
現(xiàn)在,右鍵點擊App.java。選擇Run檔選項。你會看到在NetBeans控制臺的結(jié)果。
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:MVNconsumerBankingsrcmainesources [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 ------------------------------------------------------------------------