Class ModuleSystemExamples

java.lang.Object
net.jrodolfo.java_evolution.java09.module_system.ModuleSystemExamples

public class ModuleSystemExamples extends Object
Demonstrates the Java Platform Module System (JPMS), introduced in Java 9.
  • Constructor Details

    • ModuleSystemExamples

      public ModuleSystemExamples()
  • Method Details

    • createModularSourceTree

      public void createModularSourceTree(Path sourceRoot) throws IOException
      Creates a small modular source tree with one library module and one application module.
      Parameters:
      sourceRoot - root directory for the module source tree
      Throws:
      IOException - when source files cannot be written
    • createSourceTreeWithInternalPackageAccess

      public void createSourceTreeWithInternalPackageAccess(Path sourceRoot) throws IOException
      Creates a modular source tree where the app module incorrectly imports an unexported package from the greetings module.
      Parameters:
      sourceRoot - root directory for the module source tree
      Throws:
      IOException - when source files cannot be written
    • compileModules

      public ModuleSystemExamples.CommandResult compileModules(Path sourceRoot, Path moduleOutputDirectory) throws IOException, InterruptedException
      Compiles all module source files under a module source root.
      Parameters:
      sourceRoot - root containing module directories
      moduleOutputDirectory - output directory for compiled modules
      Returns:
      compiler process result
      Throws:
      IOException - when the compiler cannot be started or source files cannot be listed
      InterruptedException - when interrupted while waiting for the compiler
    • runApplicationModule

      public ModuleSystemExamples.CommandResult runApplicationModule(Path moduleOutputDirectory) throws IOException, InterruptedException
      Runs the modular application.
      Parameters:
      moduleOutputDirectory - directory containing compiled modules
      Returns:
      Java process result
      Throws:
      IOException - when the child JVM cannot be started
      InterruptedException - when interrupted while waiting for the child JVM