Sunday Aug 25, 2013

Eclipse Formatter for NetBeans IDE (Part 1)

Several times I've been told that the only major blocker to considering NetBeans IDE as a viable alternative is that Java formatting rules have been defined in Eclipse and that those formatting rules cannot be imported into NetBeans IDE.

Well, Willie Scholtz from South Africa has solved this problem:

And I followed the instructions in his blog and I now have a plugin that provides the possibility to integrate an Eclipse XML formatting file into NetBeans IDE:

Here's how it works. Install the plugin into NetBeans IDE 7.3.1 (should also work in later versions but haven't tried that) and then go to the Options window and register your Eclipse formatting XML file:

That's it, you're done. Now, whenever you save a Java source file, the formatting rules defined in the XML file you registered above are applied. At the moment, no checks are done to see whether the XML file is a valid Eclipse formatting file. The assumption is that you've configured Java formatting rules in Eclipse, that you exported those rules, and that you therefore have an XML file containing all those rules. That XML file is the one that you should have registered above. No restarts or anything like that is needed. Immediately after you click OK above, the formatting rules in the XML file will be applied whenever you make a change in a file and click Save.

Regardless of whether this plugin is useful to you, do you want to help by trying it out? Take the following steps, in this order:

  1. Start up NetBeans IDE 7.3.1 with a fresh user directory. And then install the plugin into NetBeans IDE 7.3.1.

  2. In the New Project wizard, go to Java | Java Application and complete the wizard. Now you have a new Java SE project with a Java source file.

  3. Go to the Options window and register an XML file on disk, named "eclipse-demo.xml", with this content:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <profiles version="1">
        <profile kind="CodeFormatterProfile" name="eclipse-demo" version="1">

    When you click OK to exit the Options window, this message in the status bar (i.e., left corner of the IDE) tells you that you have set the Eclipse formatting file, if you don't see this, you have not succeeded in setting the file:

  4. Declare the following in the Java source file:
    public enum X { A,B,C,D,E,F}

    Save the file and now you should see this:

    public enum X {

Any feedback is very welcome.

Additional references:

Update 6 September 2013: See part2 here.

Update 31 October 2013: See part 3 here.


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.


« August 2013 »