Site iconJava PDF Blog

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.

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.


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.

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.

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.

Now Open TestModuleXX in NetBeans and resolve all dependencies problems. Click on the Hint and select Search Dependency at Maven Repositories

Now My project cannot find my png file.

To solve this right click on your project and select new XML Layer and click Finish.

You should now see something like this


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


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.

Rename org/yourcomp/testmodulexx to Rename org/yourcomp/testmodule

 

Do same in your manifest.mf


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.

When all is resolved, do a clean build and your project should successfully build.

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.