-

NetBeans 6.7和更新版本对Maven具有内置支持。在以前的版本中,Maven插件在插件管理器中可用。在这个例子中我们使用的是NetBeans 6.9。

下面列出了NetBeans的一些功能

以下示例将帮助您充分利用集成NetBeans和Maven的优势。

在NetBeans中打开一个maven项目

在NetBeans中打开一个Maven项目。

现在,您可以在NetBeans中看到maven项目。查看consumerBanking项目库和测试库。您可以看到NetBeans已将Maven依赖项添加到其创建路径。

NetBeans中的Maven项目。

在NetBeans中创建一个maven项目

现在,它使用NetBeans的maven功能创建此项目。

在NetBeans中创建Maven项目。

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
------------------------------------------------------------------------

在NetBeans中运行应用程序

现在,右键单击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
------------------------------------------------------------------------