4 Building modules from source to JAR

 

This chapter covers

  • Project directory structures
  • Compiling sources from a single module to class files
  • Compiling 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 (JARs) 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’ll look at the javac and jar commands available on the command line. You may be wondering about that—aren’t IDEs and other tools going to use them for you? Likely, yes, but even putting aside the argument that it’s always good to know how those tools work their magic, there is a more important reason to get to know these commands: they’re the most direct path into the module system’s heart. We’ll use them to explore its features inside 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 about 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

4.3.6 Is it worth it?

4.4 Compiler options

4.5 Packaging a modular JAR

4.5.1 Quick recap of jar

4.5.2 Analyzing a JAR

4.5.3 Defining an entry point

4.5.4 Archiver options

Summary

sitemap