10 Steps to Get Started with Maven on the NetBeans Platform

Aside from the (currently) missing exhaustive reference material for the NetBeans Platform (mitigated by the NetBeans API javadoc and Essential NetBeans Platform Reference Card), the other BIG gap in the NetBeans Platform documentation is... everything relating to Maven. Much can be discovered via google (e.g., type the following keywords in google "NetBeans Platform Maven" and/or "NetBeans RCP Maven").

However, the official docs all assume you're using Ant to build your application. Time to fix that.

Here's a start. Simple NetBeans Platform "getting started" scenario (plus some interesting benefits over Ant) via Maven and a bunch of screenshots.

  1. Go to the New Project wizard, choose the Maven project type, and click Next:

  2. Choose the Maven NetBeans Platform Application Archetype and click Next:

  3. Enter a name for your application and other stuff, including a main package, which (just for fun) I have here specified to indicate that this application is being developed for the Skyguide team (visited by Toni and myself last year and they're doing great with the NetBeans Platform, last I heard):

  4. Click Finish and then the IDE shows you the project structure of the folders and files that have been created on disk:

  5. However, maybe you reckon that IntelliJ IDEA provides a better perspective. No worries, just open the 'pom.xml' file created for the application into the (free!) community edition of IntelliJ IDEA and then you're good to go:

    Note: Follow these steps to set up the classpath correctly for using the NetBeans Platform in IntelliJ IDEA.

  6. Use the "New Window Component" wizard in NetBeans IDE to create a new window in the application:

  7. Run the application (from wherever you like, including the command line), open a few windows, and here's the starting point of the brilliant application you're about to create:

  8. Ask yourself this simple question: "How much coding have I done to get to the above state of my application?"

    Answer:

  9. Then use the Matisse GUI Builder in NetBeans IDE to add UI elements to the window you generated earlier.

  10. Next, if that's your preference, use IntelliJ IDEA again for the coding of the business logic of your application. I.e., in this scenario, NetBeans IDE is a simplistic code generator, while IntelliJ IDEA is your code editor. The dependency graph for Maven applications is fun too:

Hurray, you're up and running with the NetBeans Platform for Maven-based applications! What should be addressed next in this Maven-based series of blog entries? Tell me and I will write it!

Comments:

It shows that NetBeans is poor for Maven project navigation and code editing. Otherwise, why would you introduce IntelliJ IDEA here.

Posted by guest on January 06, 2010 at 10:08 AM PST #

Add the following to your pom.xml to use OfficeLAF

<dependencies>
<dependency>
<groupId>org.officelaf</groupId>
<artifactId>OfficeLAF</artifactId>
<version>0.9-RELEASE67</version>
<type>nbm</type>
</dependency>
</dependencies>
<repositories>
<repository>
<id>java.net2</id>
<name>Repository hosting the jee6 artifacts</name>
<url>http://download.java.net/maven/2</url>
</repository>
</repositories>

Posted by Mikael Tollefsen on January 06, 2010 at 04:32 PM PST #

Add the following to your pom.xml to use the OfficeLAF

<dependencies>
<dependency>
<groupId>org.netbeans.cluster</groupId>
<artifactId>platform10</artifactId>
<version>${netbeans.version}</version>
<type>pom</type>
</dependency>

<dependency>
<groupId>org.officelaf</groupId>
<artifactId>OfficeLAF</artifactId>
<version>0.9-RELEASE67</version>
<type>nbm</type>
</dependency>
</dependencies>
<repositories>
<repository>
<id>java.net2</id>
<name>Repository hosting the jee6 artifacts</name>
<url>http://download.java.net/maven/2</url>
</repository>
</repositories>

Posted by guest on January 06, 2010 at 04:34 PM PST #

Hello Geertjan,

I too am trying to collect bits and pieces regarding Maven and NetBeans platform together. I started a process of migrating 3 different Swing GUIs, which are part of a bigger project built by Maven, into one integrated GUI supported by NetBeans platform. I'm using nbm-maven-plugin 3.1 to build NetBeans modules (nbm packaged artefacts).
The main problem I'm currently facing is the following:
nbm-maven-plugin packages a NetBeans module from classes/resources that are part of nbm module and adds propper NetBeans MANIFEST entries for dependent nbm modules etc. If nbm module being built is also dependent on jar modules then jar artefacts of those modules are packaged as private libraries of the nbm module. So if I have two nbm modules dependent on the same jar module, this jar module will be packaged twice as a private library of each nbm module. Besides redundancy this also has undesired effect if this jar library should be shared because it maintains internal state in static fields.
The obvious answer to this problem is to change all jar modules into nbm modules. This can be done for internal modules but our code also depends on numerous third-party libraries which are managed outside via Maven. I would not like to maintain nbm module wrappers for all those external libraries but I'm afraid there's no other alternative. Or is there and I just can't spot it?

Peter

Posted by Peter Levart on January 06, 2010 at 05:25 PM PST #

Peter, you can have a look at

http://nbpwr.kenai.com

While it started for my own needs, the idea is to have the thing used by others. For this to happen, it probably needs some work - but we'll never know if nobody else tries it.

In any case, using wrapper modules is the way to go.

@71.68.117.198 No question IDEA has got a lot of smart things, even though I personally don't see the need for using it. Keeping on with comparing IDEs and Maven, one could try to open the Maven project with Eclipse and enjoy the big mess it will make.

Posted by Fabrizio Giudici on January 06, 2010 at 07:28 PM PST #

Peter,

You should have just one module that bundles the non-module jars. If you have independent one, you might ship with 2 modules, but it's still not recommended. So for any 3rd party jars you will have to create a wrapper module that other modules depend on, it can contain code on it's own, have it's own public api etc. The other modules need to depend on this one, not the non-module jars. That's the way it works and honestly I don't see any other way around it.

The dependency resolution rules are described in the nbm plugin docs.

Milos

Posted by Milos Kleint on January 06, 2010 at 08:07 PM PST #

Hi,

Great blog, this series come just in time for my needs. :).

The Maven archetype seems to generate Netbeans 6.7 applications, so instrucctions to upgrade to 6.8 could be very helpfull, by changing platform and netbeans version in pom.xml to platform11 and release68 seem not to work.

Raul

Posted by Raul Arabaolaza on January 07, 2010 at 09:20 PM PST #

Hello,
Can you explain how to import a maven project into Netbeans ?
Regards,

Posted by José Luis Sánchez on January 08, 2010 at 02:09 AM PST #

has anybody tried and succeded in creating a jee client application on top of 6.8 with a maven build ? preferably without wiring to the specific server jars (altough I use jee6 so right now I don't have much of choice ;])

Posted by psychollek on January 09, 2010 at 07:15 AM PST #

good to know that maven based netbeans platform development is getting more focus. any idea if it will (hopefully) be the 'default' way for developing netbeans RCP applications?

would be good to have more tutorials/docs on:

- reference to map netbeans API dependencies (i.e. Datasystems API, Lookup API, Projects API, Projects UI API, etc.) to Maven dependencies

- how to exclude certain module dependencies when using a specific cluster.

- well, basically all the configurations that we can do from nb rcp project's 'important files' that we now have to tweak from pom.xml... how's it done....

its a lot of guesswork and experiments now...

Posted by jdbmonitor on January 17, 2010 at 07:50 AM PST #

If the NetBeans team ever tries to make Maven the "default", then enterprising developers such as myself will fork the code base and strip out any reference to the worst build tool (Maven) that ever was.

Posted by you-wanna-fork-the-RCP on January 22, 2010 at 03:24 PM PST #

Can u write about importing a maven project to netbeans from a remort repository like in the case of Funambol. And I wanna know whether Maven 3.1 and above is backward compatible. That's to say, the stuff like Funambol V8 which is primarily based on maven 2.0 would work with the newer versions of maven and in netbeans in particular.
Many Thanks in advance
Jani

Posted by Jani-the-Newbee on November 07, 2010 at 01:55 PM PST #

Netbeans 7.0 + ,include full support for maven. So it makes easy to import maven projects. very informative tutorial sir. Thank you

Posted by akshay on December 26, 2013 at 01:16 AM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
24
25
26
27
28
29
30
   
       
Today