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
6
votes
1 answer

Find the missing module

My question: when building a minimal JRE, how can one make sure that no required module is missing? To illustrate the question, here is an example where I want to build a minimal JRE for my project. Let's assume for this example that logback is my…
assylias
  • 321,522
  • 82
  • 660
  • 783
6
votes
0 answers

How to debug Java runtime unnamed modules errors with hashed names

I'm into modular Java for a few months now, with Spring and related ecosystem stuff. And one of the most frustrating experiences is debugging module issues with unclear names Here is the last error of this kind I got: java.lang.IllegalAccessError:…
Salathiel Genese
  • 1,639
  • 2
  • 21
  • 37
6
votes
1 answer

Java 11 unnamed module issue when using Maven model

So, I'm trying to migrate a tool from Java 8 to Java 11. I did the first step to make it work without modules and the code compiles successfully. Now I'm trying to add the module-info.java, and I first faced issues because of the libraries used in…
Xendar
  • 466
  • 1
  • 6
  • 15
6
votes
1 answer

Netbeans Swing GUI Builder not working with java-module project and Maven

I want to use Netbeans' Swing GUI builder together with a Maven project and java modules. It seems like the GUI Builder can not find the compiled classes if they are compiled as part of a java module. It gives the error "Error in loading component…
foolo
  • 804
  • 12
  • 22
6
votes
0 answers

Java 9: run legacy jar

I have a jar built before Java 9. I'm trying to run a class that is in that jar using Java 9. From all I read about automatic modules, this should work: java -p lib/Legacy-1.3.0.jar -m Legacy/com.blah.MyClass But instead I get this: Error: Unable…
Bob Woodley
  • 1,246
  • 15
  • 30
6
votes
1 answer

Patching module raises module not found error

I use jdk 11 and try to understand --patch-module option for java compiler. Here is the simple module I have: mdl-platform | | |___com.test.mdl.platform | | | |___ ... | | | …
St.Antario
  • 26,175
  • 41
  • 130
  • 318
6
votes
2 answers

How to generate an executable of a modular Java app with javapackager?

Environment: Win10, Oracle JDK 9, Eclipse, jlink, javapackager Context: I'm trying to generate an executable file with javapackager having a java custom runtime image made with jlink, reading the javapackager documentation. Not an…
tec
  • 999
  • 3
  • 18
  • 40
6
votes
2 answers

Compile a JDK 8 project + a JDK 9 "module-info.java" in Gradle

I'm working on a Java library targeting JDK 8, and I'm building it in Gradle 5 using OpenJDK 11. In order to target JDK 8, I'm javac's --release option. However, I'd also like my library to be JPMS-compatible. In other words: I'd like to provide a…
Tomasz Linkowski
  • 4,386
  • 23
  • 38
6
votes
2 answers

How to expand the module path at runtime

I like services. I also like the module system. Unfortunately for me, before I used Java 9 I got in the habit of getting service providers from jars loaded at runtime via URLClassLoader, something like this (I'll use Java 10's var for brevity): var…
Anonymous
  • 491
  • 2
  • 12
6
votes
2 answers

Is `sun.awt.image` package deprecated?

I wanted to use some codes that using sun.awt.image.PNGImageDecoder in my project. The problem is source code is based on Java 8 and my project using JDK 9+ (11). So I got this error: Package 'sun.awt.image' is declared in module 'java.desktop',…
Mir-Ismaili
  • 13,974
  • 8
  • 82
  • 100
6
votes
1 answer

Why is my Java9 module service not working?

--------------------------------------------- package org.zpf.service; public interface Services { void test(); } module org.zpf.service.Services { exports org.zpf.service; } --------------------------------------------- package…
6
votes
1 answer

Gradle for Java 11 with Modules

I'm trying to run a sample JavaFX app on Mac OS. build.gradle apply plugin: 'java' apply plugin: 'application' repositories { mavenCentral() } dependencies { compile "org.openjfx:javafx-base:11" compile…
DbSchema
  • 413
  • 5
  • 16
6
votes
0 answers

package x is declared in the unnamed module, but module x does not read it

I want to migrate to Java 11 and JFX11 using netbeans. JFX11 must be used as module, so I have added the JavaFX jars and added the following in my module-info.java under the default package folder. requires javafx.controls; requires…
Dodd10x
  • 3,344
  • 1
  • 18
  • 27
6
votes
1 answer

Where has sun.misc.Perf moved now that tools.jar was decomposed in Java 9

sun.misc.Perf was in tools.jar and in Java 9 this was removed and restructured based on the modules concept, so the question is how do you access it in newer Java? I need to know which module now contains this code.
Alexandros
  • 2,097
  • 20
  • 27
6
votes
0 answers

How do I add the `exports` or the `opens` for those resources so that other modules can load them?

I'm writing a module-info.java for Ikonli's Fontawesom5 module, org.kordamp.ikonli.fontawesome5. That jar has some resources that need to be accessed:…
Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622