Mark Stephens Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX. He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

Making your Java code more modular in NetBeans

1 min read

At the recent NetBeans Greece Day, I heard a very interesting talk on using NetBeans in agile development, mapping each new feature onto a module. This made me think about whether I could make better use of the NetBeans modules….

The problem with any coding activity is that it tends to grow and sprawl. Our company (IDR Solutions) code base has expanded over the years and we now have several products using different parts of the code. In our case, we have a PDF to HTML5 converter, a Swing GUI, a JavaFX PDF viewer, lots of serverside code examples. Initially we just deleted the bits not needed for each build but this has become increasingly brittle and hard to maintain. So here is what I did….

NetBeans module
Making the code more modular using NetBeans

The shared code is now in a core module, which in our case is low level code to read and decode PDF files. We have extracted the image code we use into a separate library (the new JDeli image library). All the code for the JavaFX PDF viewer is now in the javafx module. This makes it much easier for us to separate out the different parts of the application and also to create specific customer builds.

The jpedal module provides the builds for our JPedal PDF Library users and the jpdf2html5 provides the separate PDF to HTML5 converter (shared code is in the core module).

We actually have a special build for several customers. Adobe uses JPedal in ColdFusion, so there is an Adobe module which allows us to build and test their version and keep any specific Adobe code there. We can easily give them HTML or XFA features by adding the module to their build.

We still provide our customers with a single jar or zipped src of either the PDF library or the PDF to HTML5 converter. But it makes it much easier for us to test and maintain internally. Because NetBeans modules can be just a simple wrapper around a Maven project, this also allows you to convert your code base very easily into a set of Maven projects.

Testing is also vastly improved because the code exactly matches what is in the IDE. Continuous integration tests can now be far more precise – changes to the jpdf2html5 code do not run tests related to PDF viewer or PDF to Image. Only core changes will run all the tests (as core changes could impact everything).

So if you have a Java project which has ‘grown’, I recommend you have a look at splitting the code into specific NetBeans modules as a way to tidy up and modularize your code. It has worked very well for us.

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.

Mark Stephens Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX. He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

Leave a Reply

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