Creating a Maven project with NetBeans 7

Much like Eclipse, NetBeans is an open source platform-framework and an IDE (Integrated Development Environment) for developing with Java and other technologies.

It is a free and open source software maintained by the NetBeans community and backed by Sun/Oracle Corporation. According to http://netbeans-org:

"The NetBeans IDE is written in Java and runs everywhere where a JVM is installed, including Windows, Mac OS, Linux, and Solaris… The NetBeans Platform allows applications to be developed from a set of modular software components called modules. Applications based on the NetBeans platform (including the NetBeans IDE) can be extended by third party developers."

The Maven module will either be pre-included in your NetBeans installation or can be installed on top of the NetBeans IDE.

The Maven module comes with an embedded instance of Maven or alternatively can be configured to work with one or more standalone instances of Maven.

It provides comprehensive integration between NetBeans and Maven, and you the developer could almost do without executing Maven commands from the terminal/console.

Getting ready

Download the NetBeans 7 bundle for Java EE from the NetBeans website.

http://netbeans.org/downloads/index.html

Install NetBeans 7 and configure your Maven home directory in Tools | Options | Miscellaneous | Maven.

Getting ready

If you have an existing Apache Maven installation, you can point to that or continue to use the bundled version of Apache Maven.

How to do it...

Launch the New Project wizard by selecting File | New Project and then select Maven | Java Project.

Next, specify the Maven project co-ordinates and complete the wizard:

How to do it...

Here you can enter the Project Name and Project Location on your filesystem and the Apache Maven project co-ordinates.

The Artifact ID is picked up from the project name, while the text fields for Group Id, Version, and Package can be edited.

On completion, a new project will be created, which is both a NetBeans project and an Apache Maven project.

NetBeans directly integrates with the Maven build lifecycle and provides you with a range of options to quickly clean, build, and execute your project under the Run and Debug menu options:

How to do it...

To create a custom Maven goal execution configuration, right-click the project, select Custom | Goals, and define your custom goal:

How to do it...

Apart from specifying the custom goal, you can also define Profiles and custom Properties for the custom run configuration.

Select the checkbox at the bottom to save this configuration for future use.

How it works...

We just created a project that is a NetBeans and Maven-compatible project. If you inspect the filesystem, you will find that a valid pom.xml file exists in the project root, which makes it a valid Maven project:

How it works...

The presence of a project POM file makes it a valid NetBeans project, as NetBeans is fully compatible with the configurations in the POM.

In addition to the pom.xml file, you will also find the nbactions.xml file, which is a NetBeans-specific file, to store the custom goal/execution configuration.

Once you execute the project clean, build, run, or custom Maven goal, NetBeans starts a read-only console at the project root. The appropriate Maven goals are executed using Maven APIs and the output is shared on the read-only console.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.69.185