How to manage Maven Project in NetBeans and IntelliJ IDEA

Last updated on May 27 2022
Mrinalini Pandey

Table of Contents

How to manage Maven Project in NetBeans and IntelliJ IDEA

Maven – NetBeans

NetBeans 6.7 and newer has in-built support for Maven. In case of previous version, Maven plugin is available in plugin Manager. We are using NetBeans 6.9 in this example.
Some of features of NetBeans are listed below −
• You can run Maven goals from NetBeans.
• You can view the output of Maven commands inside the NetBeans using its own console.
• You can update maven dependencies with IDE.
• You can Launch Maven builds from within NetBeans.
• NetBeans does the dependency management automatically based on Maven’s pom.xml.
• NetBeans resolves Maven dependencies from its workspace without installing to local Maven repository (requires dependency project be in equivalent workspace).
• NetBeans automatic downloads required dependencies and sources from the remote Maven repositories.
• NetBeans provides wizards for creating new Maven projects, pom.xml.
• NetBeans provides a Maven Repository browser that enables you to view your local repository and registered external Maven repositories.
Subsequent example will help you to leverage benefits of integrating NetBeans and Maven.

Open a maven project in NetBeans

• Open NetBeans.
• Select File Menu > Open Project option.
• Select Project location, where a project was created using Maven. We’ve created a Java Project consumerBanking. Go to ‘Creating Java Project’ chapter, to see how to create a project using Maven.

Page 2 Image 1 10
Creating Java Project

Now, you can see the maven project in NetBeans. Have a look at consumerBanking project Libraries and Test Libraries. You can see that NetBeans has added Maven dependencies to its build path.

Page 2 Image 2 20
consumerBanking

Build a maven project in NetBeans

Now, Its time to build this project using maven capability of NetBeans.
• Right Click on consumerBanking project to open context menu.
• Select Clean and Build as option.

Page 3 Image 3 6
Clean and Build

Maven will start building the project. You can see the output in NetBeans Console as follows −
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

Run Application in NetBeans

Now, right click on App.java. Select Run File as option. You will see the result in the NetBeans Console.
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 ongoing-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: [ongoing-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
————————————————————————

Maven – IntelliJ IDEA IDE Integration

IntelliJ IDEA has in-built support for Maven. We are using IntelliJ IDEA Community Edition 11.1 in this example.
Some of the features of IntelliJ IDEA are listed below −
• You can run Maven goals from IntelliJ IDEA.
• You can view the output of Maven commands inside the IntelliJ IDEA using its own console.
• You can update maven dependencies within IDE.
• You can Launch Maven builds from within IntelliJ IDEA.
• IntelliJ IDEA does the dependency management automatically based on Maven’s pom.xml.
• IntelliJ IDEA resolves Maven dependencies from its workspace without installing to local Maven repository (requires dependency project be in equivalent workspace).
• IntelliJ IDEA automatically downloads the required dependencies and sources from the remote Maven repositories.
• IntelliJ IDEA provides wizards for creating new Maven projects, pom.xml.
Subsequent example will help you to leverage benefits of integrating IntelliJ IDEA and Maven.

Create a new project in IntelliJ IDEA

We will import Maven project using New Project Wizard.
• Open IntelliJ IDEA.
• Select File Menu > New Project Option.
• Select import project from existing model.

Page 7 Image 4 1
existing model

• Select Maven option

Page 7 Image 5 1
Maven

• Select Project location, where a project was created using Maven. We have created a Java Project consumerBanking. Go to ‘Creating Java Project’ chapter, to see how to create a project using Maven.

Page 8 Image 6
Creating Java Project

• Select Maven project to import.

Page 9 Image 7
Select Maven

• Enter name of the project and click finish.

Page 9 Image 8
finish

• Now, you can see the maven project in IntelliJ IDEA. Have a look at consumerBanking project external libraries. You can see that IntelliJ IDEA has added Maven dependencies to its build path under Maven section.

Page 10 Image 9
Maven dependencies

Build a maven project in IntelliJ IDEA

Now, it’s time to build this project using capability of IntelliJ IDEA.
• Select consumerBanking project.
• Select Buid menu > Rebuild Project Option
You can see the output in IntelliJ IDEA Console
4:01:56 PM Compilation completed successfully

Run Application in IntelliJ IDEA

• Select consumerBanking project.
• Right click on App.java to open context menu.
• select Run App.main()

Page 11 Image 10
Run App.main()

You will see the result in IntelliJ IDEA Console.
“C:\Program Files\Java\jdk1.6.0_21\bin\java”
-Didea.launcher.port=7533
“-Didea.launcher.bin.path=
C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 11.1.2\bin”
-Dfile.encoding=UTF-8
-classpath “C:\Program Files\Java\jdk1.6.0_21\jre\lib\charsets.jar;

C:\Program Files\Java\jdk1.6.0_21\jre\lib\deploy.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\javaws.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\jce.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\jsse.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\management-agent.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\plugin.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\resources.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\rt.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\ext\dnsns.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\ext\localedata.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\ext\sunjce_provider.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\ext\sunmscapi.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\ext\sunpkcs11.jar

C:\MVN\consumerBanking\target\classes;
C:\Program Files\JetBrains\
IntelliJ IDEA Community Edition 11.1.2\lib\idea_rt.jar”
com.intellij.rt.execution.application.AppMain com.companyname.bank.App
Hello World!

Ongoing finished with exit code 0

So, this brings us to the end of blog. This Tecklearn ‘How to manage Maven Project in NetBeans and IntelliJ IDEA’ blog helps you with commonly asked questions if you are looking out for a job in DevOps. If you wish to learn Maven and build a career in DevOps domain, then check out our interactive, Maven Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

Maven

Maven Training

About the Course

Tecklearn has specially designed this Maven Training Course to advance your skills for a successful career in this domain. The course will cover different components of Maven and how they are used in software development operations. You will get an in-depth knowledge of these concepts and will be able to work on related demos. Upon completion of this online training, you will hold a solid understanding and hands-on experience with Maven.

Why Should you take Maven Training?

• The average salary for “ant maven” ranges from approximately $71,430 per year for Entry Level Engineer to $126,916 per year for Development Operations Engineer. – Indeed.com
• According to Grand View Research, the DevOps market size is estimated to be worth $12.85 billion by 2025. DevOps professionals are highly paid and in-demand throughout industries including retail, eCommerce, finance, and technology.

What you will Learn in this Course?

Introduction to DevOps

• What is Software Development
• Software Development Life Cycle
• Why DevOps?
• What is DevOps?
• DevOps Lifecycle
• DevOps Tools
• Benefits of DevOps
• How DevOps is related to Agile Delivery
• DevOps Implementation

Maven

• Maven
• Maven Directory
• Maven Lifecycle
• Maven Dependencies
• Maven Repositories
• Phases and Goals

0 responses on "How to manage Maven Project in NetBeans and IntelliJ IDEA"

Leave a Message

Your email address will not be published. Required fields are marked *