Questions tagged [java-module]

Refers to the module as defined by the Java Platform Module System in Java 9+.

A module in the Java Platform Module System is a named, self-describing collection of code and data. Its code is organized as a set of packages containing types, i.e., Java classes and interfaces; its data includes resources and other kinds of static information. The only module known specifically to the module system, in any case, is the base module, which is named java.base.

A module is described using a , which itself is a new construct added in to provide a module definition.

Module names, like package names, must not conflict. The recommended way to name a module is to use the reverse-domain-name pattern that has long been recommended for naming packages. The name of a module will, therefore, often be a prefix of the names of its exported packages, but this relationship is not mandatory.

Module declarations are part of the Java programming language, rather than a language or notation of their own, for several reasons. One of the most important is that module information must be available at both compile time and run time in order to achieve fidelity across phases, i.e., to ensure that the module system works in the same way at both compile time and run time. This, in turn, allows many kinds of errors to be prevented or, at least, reported earlier—at compile time—when they are easier to diagnose and repair.

The Java SE 9 Platform Specification uses the module system to divide the platform into a set of modules. An implementation of the Java SE 9 Platform might contain all of the platform modules or, possibly, just some of them.


A java.lang.Module represents a run-time module, either named or unnamed.

Named modules have a name and are constructed by the Java Virtual Machine when a graph of modules is defined to the Java virtual machine to create a module layer.

An unnamed module does not have a name. There is an unnamed module for each ClassLoader, obtained by invoking its getUnnamedModule method. All types that are not in a named module are members of their defining class loader's unnamed module.

The package names that are parameters or returned by methods defined in this class are the fully-qualified names of the packages as defined in section 6.5.3 of The Java™ Language Specification, for example, java.lang.

727 questions
17
votes
2 answers

fatal error compiling invalid flag --module-path

I have a project. Originally it was a single module project with structure like this java-cloud-sample\ src\ main\ java pom.xml I decided to make it into a multi-module structure - I use java 9 anyway. So I separated it…
lapots
  • 12,553
  • 32
  • 121
  • 242
16
votes
2 answers

When JRE was completely discontinued as a separate offering?

Starting from Java 9 the module system was introduced, making provision of JRE separately redundant. Through, it seems that it was still possible to download it. For example, from here now Java 9 archive Also, here it's only stated that…
anasmi
  • 2,562
  • 1
  • 13
  • 25
16
votes
1 answer

Java 9 migration issue - package com.mymodule is declared in unnamed module , module 'newmodule' does not read it

I have created a multimodule project with the following structure myproject |- mymodule |- src |- main |- java |- com |- mymodule |-…
learner
  • 332
  • 2
  • 6
  • 22
16
votes
1 answer

Groovy Java 9 modules support

I've spent some time to migrate my project written in Groovy to Java 10. Now it's possible to compile and run it. But still it doesn't use any benefits of Java 9 modularity. Googling about Groovy and Java 9 modules gives almost nothing. So is it…
16
votes
1 answer

Java 9: Module java.xml.bind is not accessible in Eclipse

I migrating a maven project in Java 8 to a Java 9 project without any build tool in Eclipse OxyGen 1a. So my module-info.java looks like this: But java.xml.bind is not accessible, although its in my module path: So what is wrong here?
user3133542
  • 1,695
  • 4
  • 21
  • 42
15
votes
2 answers

Unable to derive module descriptor: Provider {class X} not in module

I am getting this error message when I try to compile my new modularized Java 11 application: Error occurred during initialization of boot layer java.lang.module.FindException: Unable to derive module descriptor for…
Wige
  • 3,788
  • 8
  • 37
  • 58
15
votes
1 answer

How to make Multi-Release JAR Files with Gradle?

Java9 introduces with Multi-Release JARs. Let's say that I have multimodule Gradle project using java8: project-root settings.gradle build.gradle /module1 /src ... (common maven structure) /module2 …
igr
  • 10,199
  • 13
  • 65
  • 111
15
votes
3 answers

Can I require Java 9 module via MANIFEST.MF?

My Java library should be compatible with Java 8 and Java 9. For running with Java 9 we need some of the Java 9 modules. I know that I can add it via command line with --add-modules. But it is a library and I can't control the command line. Is there…
Horcrux7
  • 23,758
  • 21
  • 98
  • 156
14
votes
4 answers

Error occurred during initialization of boot layer

I followed the steps to create the HelloWorld example but it doesn't run. It gives the following error: Error occurred during initialization of boot layer java.lang.module.FindException: Error reading module: F:\Develop\eclipse\HelloWorld\bin…
B.Sarkar
  • 139
  • 1
  • 2
  • 8
14
votes
1 answer

Illegal reflective access when I stop SpringBoot web application with Tomcat 9 and Java10

I'm trying Java 10 development with Spring Boot 2 and I encounter some issues. The application is a simple webapp based upon Spring Boot 2. The application launch is ok but when I stop it, I get this warning: WARNING: An illegal reflective access…
ChriX
  • 951
  • 4
  • 9
  • 22
14
votes
1 answer

Incompatible types, equality constraints and method not found during Java 9 Migration

While migrating one of our projects to Java 9(build 9+181), I am facing a peculiar problem what looks like an incorrect implementation in some library in use related to type inference and java-module. I am using a dropwizard-core(1.1.0) and…
Naman
  • 27,789
  • 26
  • 218
  • 353
13
votes
2 answers

How split packages are avoided in Java 9

I am new to Java 9 and was going though the modular video lectures by Java on YouTube. They mentioned 3 benefits of modularization- 1. No missing dependencies 2. No cyclic dependnpcies 3. No split packages. As far as I understand about split…
13
votes
1 answer

Why does Maven shade plugin remove module-info.class?

I try to use maven-shade-plugin for a modular jar: org.apache.maven.plugins maven-shade-plugin 3.1.1
Mordechai
  • 15,437
  • 2
  • 41
  • 82
13
votes
3 answers

How to suppress the "requires transitive directive for an automatic module" warning properly?

After upgrading a Maven project to Java 9 and adding a module descriptor, javac complains about a transitive dependency for an automatic module: [WARNING] /.../src/main/java/module-info.java:[3,35] requires transitive directive for an automatic…
Alex Shesterov
  • 26,085
  • 12
  • 82
  • 103
13
votes
1 answer

Java9 JNLP --add-opens not working

I have created a simple test case to test Java 9 Web Start with the new modules. Unfortunately, Java 9 Web Start does not by default support --permit-illegal-access like regular Java 9 does. Java 9 Web Start is suppose to support --add-opens (see…