Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Using Maven and IntelliJ IDEA to Create NetBeans Platform Applications

DZone's Guide to

Using Maven and IntelliJ IDEA to Create NetBeans Platform Applications

· Java Zone
Free Resource

Download Microservices for Java Developers: A hands-on introduction to frameworks and containers. Brought to you in partnership with Red Hat.

I'm creating a NetBeans Platform application called "Adito Designer", which is used to customize the main application, named "Adito" (a customer-relationship management software). By "customizing" I mean defining how things work in Adito and what is shown in Adito. For example, you can set up frames in Adito by dragging buttons and textfields onto a workspace in the Adito Designer and by writing Javascript to define what exactly happens when something interacts with something else. Besides that, a lot of configuration can be done in Adito Designer, by choosing and setting up the database for defining localizations. So, Adito Designer is pretty much similar to NetBeans IDE. It's an application for creating an application. It's not as universal as NetBeans IDE, though, but there are many intersections.

While that application already existed as a Swing application, it got pretty large and hard to maintain, with a few "I-hope-I-never-have-to-touch-this-again-areas", as well as being difficult to extend. So it got time for a fundamental reconstruction. After a few weeks of examining possible frameworks, the NetBeans Platform was chosen, for various reasons. A prerequisite was that the framework had to be usable within Intellij IDEA, since we have been using that IDE here for 8 years now. Asking Aunt Google soon brought me to this article on NetBeans Zone , as well as this blog entry. After some tests, it was found that our requirements could be easily archieved via Maven. As a bonus, I got dependency management and a defined project structure.

So, speaking of Maven. Maven is great and the NBM plugin for Maven for packing your NetBeans Platform project is great, too. It simply works. But, using Maven, it seems that the only way to run your application is by firing up a Maven build, which then runs through all your modules, checks whether something changed for compilation, compiles, then (no matter what) rebundles the modules as ZIP and then (after only 30 seconds) starts your application. Looking at this article again on NetBeans Zone, I got the impression that there must be a better way. So I ended up writing a simple starter:

import org.netbeans.Main;

import java.io.File;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class NbpStarter
{

private final static String WORKDIR = "myapp/target/";
private final static String DEPLOY = WORKDIR + "myappname/";

public static void main(String[] pArgs) throws Exception
{
System.setProperty("netbeans.logger.console", "true"); // for logging on the console
System.setProperty("netbeans.user", WORKDIR + "userdir"); // settings are stored here
System.setProperty("netbeans.home", DEPLOY + "platform11"); // the netbeans cluster.

System.setProperty("sun.awt.keepWorkingSetOnMinimize", "true"); // maven set this per default on starting

String[] fixedArgs = {
"--branding", "myappname"
};

LinkedList list = new LinkedList();
list.addAll(Arrays.asList(fixedArgs));
list.addAll(Arrays.asList(pArgs));

// cleanup usercache (otherwise problems arise. cache seems to be not written correctly).
_deleteUserCache();

Main.main(_listToArray(list));
}

private static String[] _listToArray(List pList)
{
return pList.toArray(new String[pList.size()]);
}

private static void _deleteUserCache()
{
_delete(new File(WORKDIR + "userdir/var/cache"));
}

private static boolean _delete(File pPath)
{
if (pPath.exists())
{
File[] files = pPath.listFiles();
for (File file : files)
{
if (file.isDirectory())
_delete(file);
else
//noinspection ResultOfMethodCallIgnored
file.delete();
}
}
return (pPath.delete());
}

}

Suddenly I was able to start my NetBeans Platform application just by hitting the "Run" button in IntelliJ IDEA! Debugging worked like a charm, too. The last problem I had was branding. Adding "myapp/target/myappname/myappname/core/locale" and "myapp/target/myappname/myappname/modules/locale" to the classpath of the starter solved that problem as well.

 

Download Modern Java EE Design Patterns: Building Scalable Architecture for Sustainable Enterprise Development.  Brought to you in partnership with Red Hat

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}