How to convert an Ant NetBeans Plugin to a Maven NetBeans Plugin

At IDR Solutions I spend a lot of time on working on the development of our Java PDF Library. Click here to read why we converted from Ant to Maven.

For this tutorial, I will create a simple NetBeans plugin with an Action that pop’s up a ‘Hello NetBeans Plugin’ when clicked.

Screen Shot 2015-06-03 at 14.41.44
Each time you Build or Run the Plugin, note that it is built with Ant. You can always check the console out put to verify.

Screen Shot 2015-06-03 at 14.46.33

Before we convert this project to maven, we have to be aware of the Maven Directory structure and where which file should be placed.
Lets have a look at the image of this Maven Project Below.

Screen Shot 2015-06-03 at 14.58.04
As shown in the diagram above, all Java packages need to reside in the java folder, manifest will be in nbm and xml, png, jpg, pdf, etc goes in to the resources folder.

So Let’s Start Converting

First of make a zip copy of your Ant project so you can always go revert back. In NetBeans, lets create a new Maven Plugin Module, this time i will call it TestMavenXX change the Group ID to the code base name of your Ant Plugin and click next and Finish.

Screen Shot 2015-06-03 at 15.48.51
Now open the two projects folders from your NetBeansProjetcs folder. Copy and paste all java file from TestModule to TestModuleXX/src/main/java/xx/xx/xx.

Screen Shot 2015-06-03 at 16.53.14
Now Open TestModuleXX in NetBeans and resolve all dependencies problems. Click on the Hint and select Search Dependency at Maven Repositories

Screen Shot 2015-06-03 at 17.06.01
Now My project cannot find my png file.

Screen Shot 2015-06-03 at 17.08.34
To solve this right click on your project and select new XML Layer and click Finish.

Screen Shot 2015-06-03 at 17.14.36
You should now see something like this

Screen Shot 2015-06-03 at 17.19.33

You can now copy and paste all non java files excluding Bundle.properties from TestModule/src/org/yourcomp/testmodule to TestModuleXX/src/main/resources/org/yourcomp/testmodulexx

Screen Shot 2015-06-03 at 17.30.10

At this stage we can delete the TestMaven Project.Once done Right click on TestModuleXX in NetBeans and select Rename. You can Rename it to TestModule now.

Screen Shot 2015-06-03 at 17.33.34
Rename org/yourcomp/testmodulexx to Rename org/yourcomp/testmodule

Screen Shot 2015-06-03 at 17.14.36
 

Screen Shot 2015-06-03 at 17.42.28
Do same in your manifest.mf

Screen Shot 2015-06-03 at 17.57.08

Now do a Clean and Build on your project. If you get an error like this
Project uses classes from transitive module org.netbeans.api:org-openide-util:jar:RELEASE80 which will not be accessible at runtime.
Check in the imports of your java classes you should see a yellow triangular sign on one or more of your imports.To fix the problem,we need to add this module as direct dependency in our pom.xml. Once done you should see the triangle disappear.

Screen Shot 2015-06-03 at 17.50.16
When all is resolved, do a clean build and your project should successfully build.

Screen Shot 2015-06-03 at 18.03.10
Now you can run your new NetBeans Maven plugin. If your plugin depends on some extra jars, you just need to add them as dependencies in your pom.xml and it will be automatically downloaded and installed in your project.

Hopefully you have found this quick guide useful.

If you’re a first-time reader, or simply want to be notified when we post new articles and updates, you can keep up to date by social media (Twitter, Facebook and Google+) or the Blog RSS.

Related Posts:

The following two tabs change content below.

Ernest Duodu

Developer at IDRSolutions
Ernest is a developer at IDRSolutions. He focuses mainly on our JavaFX PDF Viewer implementation. He was a speaker at JavaOne 2014, where he did a joint session titled "Lessons learnt developing a NetBeans PDF viewer plugin in JavaFX". Aside programming, he also enjoys a wide variety of hobbies which includes sky-diving, photography, exercising and listening to music.
Ernest

About Ernest Duodu

Ernest is a developer at IDRSolutions. He focuses mainly on our JavaFX PDF Viewer implementation. He was a speaker at JavaOne 2014, where he did a joint session titled “Lessons learnt developing a NetBeans PDF viewer plugin in JavaFX”. Aside programming, he also enjoys a wide variety of hobbies which includes sky-diving, photography, exercising and listening to music.

Leave a Reply

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

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>