English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Maven-NetBeans

NetBeans 6.7 Die aktualisierte Version hat Maven integriert. Für frühere Versionen können Sie das Maven-Plugin im Plugin-Zentrum herunterladen. In diesem Beispiel verwenden wir NetBeans 6.9. Here are some features of NetBeans:

  • You can run Maven targets through NetBeans.

  • You can use NetBeans' own console to view the output of Maven commands.

  • You can update the dependencies between Maven and the IDE.

  • You can start Maven's build in NetBeans.

  • NetBeans implements automated dependency management based on Maven's pom.xml.

  • NetBeans can resolve Maven's dependency issues through its own workspace without installing them in the local Maven repository, although the dependent projects are in the same workspace.

  • NetBeans can automatically download the required dependencies and source code from remote Maven repositories.

  • NetBeans provides a wizard for creating Maven projects and pom.xml files.

  • NetBeans provides a browser for Maven repositories, allowing you to view local repositories and registered external Maven repositories.

Open a Maven project in NetBeans

  • Open NetBeans

  • Select File Menu > Open Project Options

  • Select the project path, which is the storage path when creating a project with Maven. Suppose we have created a project: consumerBanking. Through Maven-Java-Projekt bauen See how to create a project using Maven.

So far, you can already see the Maven project in NetBeans. Look at the Libraries and Test Libraries of the consumerBanking project. You will find that NetBeans has already added all the dependencies of Maven to its build path.

Build a Maven project in NetBeans

Alright, let's use NetBeans' compilation feature to build this Maven project

  • Right-click on the consumerBanking project to open the context menu.

  • Select the "Clean and Build" option

Maven will start building this project. You can view the output log information in the NetBeans terminal:

NetBeans: Ausfühing von '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]
[WARNUNG] Verwendung der Plattform-Kodierung (Cp1252 tatsächlich)
zu kopieren, d.h. der Build ist plattformabhängig!
non existing resourceDirectory C:\MVN\consumerBanking\src\main\resources überspringen
[compiler:compile]
Kompilierung 2 source files to C:\MVN\consumerBanking\target\classes
[resources:testResources]
[WARNUNG] Verwendung der Plattform-Kodierung (Cp1252 tatsächlich)
zu kopieren, d.h. der Build ist plattformabhängig!
vermeiden Sie das Existenzproblem im Ressourcendirektorium C:\MVN\consumerBanking\src\test\resources
[compiler:testCompile]
Kompilierung 1 Quelldatei in C:\MVN\consumerBanking\target\test-classes
[surefire:test]
Surefire-Berichtsverzeichnis: C:\MVN\consumerBanking\target\surefire-berichte
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.companyname.bank.AppTest
Durchgefuhrte Tests: 1, Fehlschläge: 0, Fehler: 0, übersprungen: 0, Zeit verstrichen: 0.023 sec
Ergebnisse:
Durchgefuhrte Tests: 1, Fehlschläge: 0, Fehler: 0, übersprungen: 0
[jar:jar]
Erstellung von Jar: C:\MVN\consumerBanking\target\consumerBanking-1.0-SNAPSHOT.jar
[install:install]
Installierung von C:\MVN\consumerBanking\target\consumerBanking-1.0-SNAPSHOT.jar
in C:\Users\GB3824\.m2\repository\com\companyname\bank\consumerBanking\
1.0-SNAPSHOT\consumerBanking-1.0-SNAPSHOT.jar
------------------------------------------------------------------------
BUILD ERFOLGREICH
------------------------------------------------------------------------
Gesamte Zeit: 9 Sekunden
Beendet am: Do, Jul 19 12:57:28 IST 2012
Ende Memory: 16M/85M
------------------------------------------------------------------------

Anwendung im NetBeans ausfühen

Jetzt, klicken Sie mit der rechten Maustaste auf die Datei App.java. Wählen Sie die Option 'Datei ausfühen'. Sie können das folgende Ergebnis im Terminal sehen:

NetBeans: Ausfühing von '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]
[WARNUNG] Verwendung der Plattform-Kodierung (Cp1252 tatsächlich) 
zu kopieren, d.h. der Build ist plattformabhängig!
non existing resourceDirectory C:\MVN\consumerBanking\src\main\resources überspringen
[compiler:compile]
Nichts zu kompilieren - alle Klassen sind aktuell
[exec:exec]
Hallo Welt!
------------------------------------------------------------------------
BUILD ERFOLGREICH
------------------------------------------------------------------------
Gesamte Zeit: 1 second
Beendet am: Do, Jul 19 14:18:13 IST 2012
Ende Memory: 7M/64M
------------------------------------------------------------------------