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

module-info.java for SWT cross-platform maven project

On Windows package org.eclipse.swt.win32.win32.x86_64 is used, while for Linux build it's org.eclipse.swt.gtk.linux.x86_64. If nothing is specified in module-info.java, error message is java: package org.eclipse.swt does not exist If in…
iljau
  • 2,151
  • 3
  • 22
  • 45
4
votes
1 answer

stuck on javafx.graphics does not export com.sun.javafx.sg.prism to unnamed module

I've been stuck on this error now for a few days. I've googled the heck out it and tried at least a dozen different proposed solutions in various forms... My project runs fine, UNTIL I attempt to use a specific library called MonacoFX, which,…
Michael Sims
  • 2,360
  • 1
  • 16
  • 29
4
votes
0 answers

What does "at the discretion of the host system" mean in the context of module resolution?

In two places in the package documentation for the java.lang.module package, the phrase "at the discretion of the host system" occurs. I feel like it is trying to tell me something important, and I understand the English, but I fail to see what that…
Laird Nelson
  • 15,321
  • 19
  • 73
  • 127
4
votes
1 answer

How do I dynamically load modules from a directory in Java 9+

I have been working on a software with a plugin based system, where users can write their own plugins. I am very new to JMPS, but I would like to make this using JMPS and not OSGi. Made a separate API module and even created a Test Plugin. The…
rnayabed
  • 113
  • 10
4
votes
1 answer

Use java serviceloader build with jdk8 use in >= java9

I have two jars. One provides a service interfaces and a service loading class and one provides the implementation of that service. This works perfectly when running this in jdk8, but I get an service type not accessible to unnamed module @3754a4bf…
Peter
  • 4,752
  • 2
  • 20
  • 32
4
votes
1 answer

module descriptor file allowed import statements Why?

please anyone explain me module descriptor file allowed import Why? what is the used of import statement in module descriptor file. import java.util.*; module superman { }
Ng Sharma
  • 2,072
  • 8
  • 27
  • 49
4
votes
0 answers

How to generate module-info by Annotation Processor?

I have some codes to generate some services at compiling time by java APT, before java9, I generate java source code by APT, and using Google AutoService to generate service file under META-INF/services folder, now I want to upgrade it to use Java9…
4
votes
0 answers

java.lang.module.ResolutionException

I'm trying to compile and run a modular Java project with open-jdk-11, under Eclipse. Main.java: package aubin; import java.io.File; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.bind.Unmarshaller; import…
Aubin
  • 14,617
  • 9
  • 61
  • 84
4
votes
1 answer

Module not exporting exception in javafx 12

I'm using Intellij with javafx 12, as a separate library. I managed to make it work. I made a game, and the graphics work great. Now I wanted to create a menu, with some buttons. It throws an exception when I try to add a button to the root of the…
Dusan Milosevic
  • 460
  • 2
  • 4
  • 18
4
votes
0 answers

How to load images from resources folder in a modular project in Java 9?

Environment: Eclipse, OpenJDK12, Maven, modular project. My project structure: src \main | \java | \com | | \myApp | | | \otherFolders | | | \controllers | | | …
tec
  • 999
  • 3
  • 18
  • 40
4
votes
3 answers

How to fix "Unable to derive module descriptor for .jar file" error in fxml

I would like to get an image from JAR library to my project. I've added the library to my module and…
user11383582
4
votes
1 answer

Patching java.base results in java.lang.LinkageError

I am trying to do the same thing in Java 11 that could be done with -Xbootclasspath/p:path in pre java 9. As a simple example I modified one of the valueOf methods of java.lang.Integer and compiled the project with: javac…
4
votes
1 answer

jigsaw: cannot find Kotlin symbols

I have a Java/Kotlin project with multiple sub-projects (modules). This is module-info.java for the base module: module ir.openuniverse { requires java.desktop; requires kotlin.stdlib; requires transitive org.apache.logging.log4j; …
Mir-Ismaili
  • 13,974
  • 8
  • 82
  • 100
4
votes
1 answer

JMH doesn't run inside a Java Module (Unable to find the resource: /META-INF/BenchmarkList)

I took a project that uses maven-surefire-plugin (automated tests) to trigger JMH benchmarks and added module-info.java to it. Now, META-INF/BenchmarkList is no longer getting generated (in fact, the entire directory is missing) so I end up with the…
Gili
  • 86,244
  • 97
  • 390
  • 689
4
votes
1 answer

Unable to resolve module using --module-source-path

Following up on How to define qualified exports to unknown modules? I've posted a testcase with two modules: core and plugin. core tries to expose a package to plugin using qualified exports but the compiler complains that plugin does not exist.…
Gili
  • 86,244
  • 97
  • 390
  • 689