In NetBeans Java, how do you create a multi-module project?

434 Views Asked by At

I want to create a multi-module Java project, in NetBeans 15. By "module", I mean the Java-9 "modularity" feature, where each module folder has a module-info.java file that specifies its exports or depends or etc.

I know how to code a multi-module application. I just don't know how to do it as a NetBeans project. Yet I'm sure that lots of you StackOverflow readers have been there, done that. How can I do that, too?

Also, I am not using a plug-in, I am not using JavaScript. I am not using Maven, but Ant would be OK.

There is a complete tutorial at https://netbeans.apache.org/tutorials/nbm-projecttype.html, but this shows how to create a NetBeans module, for the NetBeans IDE, so that is the wrong place to look.

1

There are 1 best solutions below

2
Daniel Cohen On

Got it! I've succeeded, I built a modular project in NetBeans.
But first, I had to understand how modules work in Java. I kept my coding as low-level as possible. I used only non-IDE file explorer, NotePad++, and Windows Command Prompt. Instead of automating the process with CMD scripts, I stuck with Java's own @argfiles. The strategy was KISS (Keep It Simple Stupid), even though the typing was brutal, I really really had to watch where and what I was typing. And plenty of times, I wished I had the NetBeans "Tools" and "Edit" features. But finally I am ready to turn to NetBeans. Yes, NetBeans does modules! Follow these steps:

  1. New project > Java with Ant > Java Modular Project.
  2. Project Name and Location is your choice.
  3. In the "Projects" window, right-click the name,
    1. New Module, and add the module name
    1. In the default package, right-click, and
      1. add your packages
      1. add your classes
      1. code your module-info
    1. another New Module etc etc
  1. eventually you'll get your modules in. NetBeans is good at catching typo's and missing items.
  2. run your multi-module program!

All this procedure is almost as easy as writing a non-module program. The extra layer of modularity should be logical and functional. For my project, I had to think twice about module boundaries and names. So! It's working. The NetBeans IDE and debugger are working for me.