Example example_requires_exports

Part of the full Java 9 Jigsaw modules example suite.

Authors

Migrated for Java Modules support documentation of Apache MavenTM in the course of the Maven Support & Care program by Gerd Aschemann (and other team members) as forked repository. Please add discussions, requirements, bugfixes, etc. to the fork instead of the original.

What is this example about?

Modules in this example

  • modb, modc, modmain

  • modmain has a Main class which is started in run.sh

  • Note the explicit --add-modules option to make sure that modb and modc are available (otherwise you will see: Exception in thread "main" java.lang.NoClassDefFoundError: pkgb/B)

Module Dependency Graph, created with DepVis

Example’s Module Dependency Graph

Example shows …​

  • Usage of requires static and requires static transitive for optional dependencies for modules, needed at compile time but don’t want to force its presence at runtime. So we mark such a dependency as being optional with the static modifier.

Output

This example uses golden master testing to ensure output consistency. The expected output is compared with actual output using verify.sh.

Expected Output

Main: pkgmain.Main, id=ID_Main_14, B: from B, C: pkgc.C, id=ID_B_12

Actual Output

Main: pkgmain.Main, id=ID_Main_14, B: from B, C: pkgc.C, id=ID_B_12

Maven 4 Output

Main: pkgmain.Main, id=ID_Main_14, B: from B, C: pkgc.C, id=ID_B_12

Maven 4 Migration

This example was migrated to Maven 4 using the standard approach documented in the central Maven 4 Migration guide. The migration required no special configuration beyond the standard Module Source Hierarchy setup.