NetBeans 6.7 版本或者更新的版本針對 Maven 支持內(nèi)部構(gòu)建功能。 針對之前的版本,可以在插件管理器中找到 Maven 插件。在本例中,我們使用 NetBeans 6.9 版本。
關(guān)于 NetBeans 的一些特性如下:
下面的例子將會幫助你更加充分的認識集成的 NetBeans 和 Maven 的優(yōu)勢。
目前為止,你已經(jīng)可以在 NetBeans 里看到 Maven 工程了??匆幌耤onsumerBanking 工程的 Libraries 和 Test Libraries. 你可以發(fā)現(xiàn) NetBeans 已經(jīng)將 Maven 所依賴的都添加到了它的構(gòu)建路徑里了。
好了,我們來使用 NetBeans 的編譯功能來構(gòu)建這個 Maven 工程
Maven 將會開始構(gòu)建該工程。你可以在 NetBeans 的終端里查看輸出的 log:
NetBeans: Executing 'mvn.bat -Dnetbeans.execution=true clean install'
NetBeans: JAVA_HOME=C:\Program Files\Java\jdk1.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:\MVN\consumerBanking\src\main\resources
[compiler:compile]
Compiling 2 source files to C:\MVN\consumerBanking\target\classes
[resources:testResources]
[WARNING] Using platform encoding (Cp1252 actually)
to copy filtered resources, i.e. build is platform dependent!
skip non existing resourceDirectory C:\MVN\consumerBanking\src\test\resources
[compiler:testCompile]
Compiling 1 source file to C:\MVN\consumerBanking\target\test-classes
[surefire:test]
Surefire report directory: C:\MVN\consumerBanking\target\surefire-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:\MVN\consumerBanking\target\consumerBanking-1.0-SNAPSHOT.jar
[install:install]
Installing C:\MVN\consumerBanking\target\consumerBanking-1.0-SNAPSHOT.jar
to C:\Users\GB3824\.m2\repository\com\companyname\bank\consumerBanking\
1.0-SNAPSHOT\consumerBanking-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 File 選項。你可以在終端看到如下結(jié)果:
NetBeans: Executing 'mvn.bat -Dexec.classpathScope=runtime
-Dexec.args=-classpath %classpath com.companyname.bank.App
-Dexec.executable=C:\Program Files\Java\jdk1.6.0_21\bin\java.exe
-Dnetbeans.execution=true process-classes
org.codehaus.mojo:exec-maven-plugin:1.1.1:exec'
NetBeans: JAVA_HOME=C:\Program Files\Java\jdk1.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:\MVN\consumerBanking\src\main\resources
[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
------------------------------------------------------------------------
更多建議: