Why did Java 9 introduce the JMOD file format?

The purpose of JMODs are not well documented and existing documentation is rather sparse. Here is an in-depth explanation of system, from my understanding. Parts of this answer are rather long, verbose, partially redundant, and a tough read. Constructive, structural, or grammatical edits are more than welcome to improve readability for future readers. Short(er) Answer … Read more

Accessing resource files from external modules

// to scan the module path ClassLoader.getSystemResources(resourceName) // if you know a class where the resource is Class.forName(className).getResourceAsStream(resourceName) // if you know the module containing the resource ModuleLayer.boot().findModule(moduleName).getResourceAsStream(resourceName) See a working example below. Given: . ├── FrameworkCore │ └── src │ └── FrameworkCore │ ├── com │ │ └── framework │ │ └── Main.java │ … Read more

How to use 3rd party library in Java9 module?

You can use your library as an automatic module. An automatic module is a module that doesn’t have a module descriptor (i.e. module-info.class). But what name do you need to specify to refer to an automatic module? The name of the automatic module is derived from the JAR name (unless this JAR contains an Automatic-Module-Name … Read more

Is it possible to mix –class-path and –module-path in javac (JDK 9)?

You can use class path and module path in parallel, but there are a few details to consider. Dependency Module Path ~> Class Path Explicit modules (JARs with a module descriptor on the module path) can not read the unnamed module (JARs on the class path) – that was done on purpose to prevent modular … Read more

Scanning classpath/modulepath in runtime in Java 9

The following code achieves module path scanning in Java 9+ (Jigsaw / JPMS). It finds all classes on the callstack, then for each class reference, calls classRef.getModule().getLayer().getConfiguration().modules(), which returns a a List<ResolvedModule>, rather than just a List<Module>. (ResolvedModule gives you access to the module resources, whereas Module does not.) Given a ResolvedModule reference for each … Read more

How to express dependency in maven on java ee features for transition to Java 9?

The Module System speaks of the way the unnamed modules as in your case of loading the application from classpath constructs the module graph. Further, from the documentation itself:- When the compiler compiles code in the unnamed module, or the java launcher is invoked and the main class of the application is loaded from the … Read more

List the modules resolved during the application startup

Module Resolution The module resolution is a two-step process. The first step recursively enumerates the ‘requires’ directives of a set of root modules. If all the enumerated modules are observable, then the second step computes their readability graph. The readability graph embodies how modules depend on each other, which in turn controls access across module … Read more

tech