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
13
votes
3 answers

java 9 module reads package X from A and B

I am trying to use spring boot with java 9 and gradle. I am unable to run my simple code, I get the below mentioned error :- Information:java: Errors occurred while compiling module 'Java9Gradle_main' Information:javac 9-ea was used to compile java…
Amar Dev
  • 1,360
  • 2
  • 18
  • 38
12
votes
3 answers

Kotlin + Java 9 modules: Module java.base cannot be found in the module graph

I'm having some issues on building a Kotlin project that uses Java 9 features. I know kotlin just allow Java 8 bytecode generation, but acording to kotlinlang.org it should support this functionality since Kotlin 1.2: The Kotlin standard library is…
NathanPB
  • 685
  • 1
  • 7
  • 22
12
votes
2 answers

Package 'com.example' reads package 'javafx.beans' from both 'javafx.base' and 'javafx.base'

In module-info.java i get the error Package 'com.example' reads package 'javafx.beans' from both 'javafx.base' and 'javafx.base'. Not only does the migration (Java 8 to Java 11) frustrate me slowly but surely, this error does not make any sense…
Hannes
  • 5,002
  • 8
  • 31
  • 60
12
votes
2 answers

Package is not visible error

I was trying to use joptsimple package in my project but I get following error: Error:(4, 20) java: package jdk.internal.joptsimple is not visible (package jdk.internal.joptsimple is declared in module jdk.internal.opt, which does not export it to…
12
votes
2 answers

Java 9: Possible to have 2 modules with same name on module path

Is it possible to have 2 modules with the exact same name (but with slightly different contents) on the module path? As far as I can tell, the Java 9 compiler does not complain about it. I have 2 modules declared as follows: module com.dj.helper { …
DJ180
  • 18,724
  • 21
  • 66
  • 117
11
votes
2 answers

Why do we need requires static in java-9 module system?

I started to learn jigsaw java-9 feature and read some articles/video. I can't understand concept of optional dependencies(requires static) quote from article: When a module needs to be compiled against types from another module but does not want…
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
11
votes
4 answers

How to fix jfoenix modules with javafx 11

So I'm adding my requires for module-info.java and finally got my program to load but as soon as tab pane wants to load from jfoenix library this error is thrown. Caused by: java.lang.IllegalAccessError: class com.jfoenix.skins.JFXTabPaneSkin (in…
exceptionsAreBad
  • 573
  • 2
  • 5
  • 17
11
votes
3 answers

Does JPMS support module version?

I thought that JPMS doesn't support module version. However, when I do java --list-modules I have the following output: java.activation@9 java.base@9 java.compiler@9 java.corba@9 java.datatransfer@9 java.desktop@9 java.instrument@9 .... So, I…
Pavel_K
  • 10,748
  • 13
  • 73
  • 186
11
votes
2 answers

Is it possible to mix Java 8 and Java 9 source code in the same project without using compiler flags?

In Java 9, you can optionally package a source directory as a module by adding a module-info.java, which defines the things packages that it exports, and which other modules it depends on. Once you do that, however, you must list ALL dependencies in…
10
votes
1 answer

Why is --add-modules necessary for modules which are on the module path?

An example: since JavaFx was dropped from the JDK, the JavaFx SDK is now distributed as a set of modular jars. To compile a JavaFx application, of course you have to put them on the module path: javac -p /path/to/jars/ App.java That doesn't…
hat
  • 781
  • 2
  • 14
  • 25
10
votes
3 answers

JAVA ERROR : package com.sun.rowset is not visible : com.sun.rowset is declared in module java.sql.rowset, which does not export it

I'm simply try to run this code: import com.sun.rowset.CachedRowSetImpl; public class Test { public static void main(String[] args) throws Exception{ CachedRowSetImpl crs = new CachedRowSetImpl(); } } When I run it I get:…
user2962142
  • 1,916
  • 7
  • 28
  • 42
10
votes
2 answers

Do Kotlin 1.2.10 and Java 9 have opposite rules regarding automatic modules?

I have a Gradle project using the Kotlin Gradle plugin. I want to build a Java 9 module, so my directory structure looks like this: src/main/java/ - module-info.java src/main/kotlin/ - Foo.kt - Bar.kt build.gradle ... My build.gradle…
0xbe5077ed
  • 4,565
  • 6
  • 35
  • 77
10
votes
1 answer

How to get module name by class in Java 9?

How to get module name by class in Java 9? For example, let's consider the following situation. There are two named modules - ModuleA and ModuleB. ModuleA knows nothing about ModuleB. ModuleB requires ModuleA. ModuleA contains class: public class…
Pavel_K
  • 10,748
  • 13
  • 73
  • 186
10
votes
2 answers

How many unnamed modules are created in Java 9?

I am trying to understand how JPMS works. From here The classpath is not completely gone yet. All JARs (modular or not) and classes on the classpath will be contained in the Unnamed Module. Similar to automatic modules, it exports all packages…
Pavel_K
  • 10,748
  • 13
  • 73
  • 186
9
votes
3 answers

Exit code: 1 - javadoc: error - The code being documented uses modules but ...... are in the unnamed module

Local Java Version is : java version "11.0.7" 2020-04-14 LTS Java(TM) SE Runtime Environment 18.9 (build 11.0.7+8-LTS) Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.7+8-LTS, mixed mode) but my project having java version of…
Remo
  • 135
  • 2
  • 11