📅  最后修改于: 2020-11-12 04:58:05             🧑  作者: Mango
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资源库浏览器,使您可以查看本地资源库和已注册的外部Maven资源库。
以下示例将帮助您利用集成NetBeans和Maven的好处。
打开NetBeans。
选择文件菜单>打开项目选项。
选择项目位置,即使用Maven在其中创建项目的位置。我们已经创建了一个Java Project ConsumerBanking。转到“创建Java项目”一章,了解如何使用Maven创建项目。
现在,您可以在NetBeans中看到maven项目。看一下ConsumerBanking项目库和测试库。您可以看到NetBeans已将Maven依赖项添加到其构建路径。
现在,是时候使用NetBeans的maven功能构建该项目了。
Maven将开始构建该项目。您可以在NetBeans Console中看到如下输出:
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
------------------------------------------------------------------------
现在,右键单击App.java。选择运行文件作为选项。您将在NetBeans控制台中看到结果。
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
------------------------------------------------------------------------