4 Building modules from source to JAR

 

This chapter covers:

  • different directory structures for a project
  • compilation of sources from a single module to class files
  • compilation of multiple modules at the same time
  • packaging class files into a modular JAR

Being able to define modules as described in chapter 3 is a good skill to have, but what is it good for without knowing how to turn those source files into modular artifacts (meaning JARs, short for Java Archives) that can be shipped and executed? This chapter looks into building modules, all the way from organizing sources, to compiling them to class files, and eventually packaging those into modular JARs that can be distributed and executed. Chapter 5 focuses on running and debugging modular applications.

At times we will look at the javac and jar commands that are available on the command line. You might be wondering about that—aren’t IDEs and other tools going to use them for you? Likely, yes, but even putting the argument aside that it is always good to know how those tools work their magic, there is a more important reason to get to know these commands: They are the most direct path into the module system’s heart. We will use them to explore its features in and out and when we’re done, you can use any tool that gives access to these features.

4.1  Organizing your project in a directory structure

4.1.1  New proposal—new convention?

4.1.2  Established directory structure

4.1.3  The place for module declarations

4.2  Compiling a single module

4.2.1  Compiling modular code

4.2.2  Modular or non-modular?

4.3  Compiling multiple modules

4.3.1  The naive approach

4.3.2  The module source path—informing the compiler of the project structure

4.3.3  The asterisk as a token for the module name

4.3.4  Multiple module source path entries

4.3.5  Setting the initial module

sitemap