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

Self-Contained Applications, built in Java

I've watched a few online presentations that briefly mentioned self-contained applications in Java 9, but I have a question that I would like cleared up. With the new module system, you're now allowed to only include the minimum amount of code…
Jacob G.
  • 28,856
  • 5
  • 62
  • 116
21
votes
1 answer

Accessing com.sun.tools.javac.util from Java 9

I'm trying to access the List class from com.sun.tools.javac.util. This works fine with Java 8, but when switching to Java 9 I get the following error: Package 'com.sun.tools.javac.util' is declared in module "jdk.compiler", which does not export it…
bramhaag
  • 628
  • 1
  • 9
  • 24
21
votes
2 answers

How to use 3rd party library in Java9 module?

I have some java9 module that uses 3rd party library that is not Java9 module, just a simple utility jar. However, the compiler complains that it can't find a package from my utility. What should I do in module-info.java to enable usage of my 3rd…
igr
  • 10,199
  • 13
  • 65
  • 111
21
votes
2 answers

Classloaders hierarchy in Java 9

As of Java 8, I know the hierarchy of the classloaders has been as follows: Bootstrap classloader → Extension classloader → Application classloader What is the change in the hierarchy of classloaders in Java 9 and how does it work?
Mohit Tyagi
  • 2,788
  • 4
  • 17
  • 29
21
votes
1 answer

Why is exporting the entire module not allowed?

In Java 9's module declaration there are 2 constructs: exports com.foo; And opens com.foo; Where exports grants compile-time access, while opens allows runtime access, as reflection and resources. opens has one leniency over exports that you can…
Mordechai
  • 15,437
  • 2
  • 41
  • 82
20
votes
3 answers

What's the purpose of 'uses' directive in Java 9?

Java's ServiceLoader class is now officially baked into the Java language. Instead of looking for providers in META-INF/services you can now use the provides with What I fail to understand is, the use of uses in the…
Mordechai
  • 15,437
  • 2
  • 41
  • 82
20
votes
2 answers

Will Cyclic Module Dependencies be Possible in Java 9?

In Java 9, will cyclic modules be allowed? If no, what are the reasons? module com.foo.bar { requires com.foo.baz; exports com.foo.bar.fizz; } module com.foo.baz { requires com.foo.bar; exports com.foo.baz.buzz; }
flakes
  • 21,558
  • 8
  • 41
  • 88
19
votes
4 answers

How can I bundle the JAXB runtime libraries with OpenJDK 11?

Background: In my organization there are a lot of Java based Windows desktop applications. In our proprietary software deployment system the applications don't contain an individual JRE / JDK. Rather a common JRE (so far Oracle 8 Java SE JRE) is…
mabu
  • 311
  • 2
  • 6
19
votes
2 answers

Where do resource files go in a Gradle project that builds a Java 9 module?

As of IDEA 2018.2.1, the IDE starts error-highlighting packages "not in the module graph" from dependencies that have been modularized. I added a module-info.java file to my project and added the requisite requires statements, but I'm now having…
David Moles
  • 48,006
  • 27
  • 136
  • 235
19
votes
2 answers

How to get list of all modules programmatically in Java 9?

How can I get list of all modules in current JVM instance via Java code? Is it possible? If yes, then how?
Pavel_K
  • 10,748
  • 13
  • 73
  • 186
19
votes
2 answers

Unable to export a package from java.base module

Using IDEA-EAP for JDK9 development experiments. I am getting the following error - Error:(3, 20) java: package jdk.internal.misc is not visible (package jdk.internal.misc is declared in module java.base, which does not export it to module…
Naman
  • 27,789
  • 26
  • 218
  • 353
18
votes
1 answer

Using SLF with Java9 modules

I set up a small test project using java 9 modules. The structure looks like this: . ├── build.gradle └── src ├── main │   └── java │   ├── module-info.java │   └── slfTest │   └── Main.java └── test …
michas
  • 25,361
  • 15
  • 76
  • 121
17
votes
1 answer

Difference between multi-module (pom) and java module system

I'm trying to understand the difference(s) between structuring a project with the Java Platform Module System (JPMS) versus structuring a project using multi-poms. Is the main difference that the JPMS encapsulates the code while a multi-pom project…
17
votes
1 answer

How to export all packages from Java 9 module?

Right now, for every module I have, I need to explicitly specify packages I want to export. For example: module core { exports cc.blynk.server.core; exports cc.blynk.server.core.protocol.handlers.decoders; exports…
Dmitriy Dumanskiy
  • 11,657
  • 9
  • 37
  • 57
17
votes
1 answer

What's the difference between Synthetic and Mandated Modifier in Java9

The Modifier for Exports in the java doc states that MANDATED The export was implicitly declared in the source of the module declaration. SYNTHETIC The export was not explicitly or implicitly declared in the source of the module…
Naman
  • 27,789
  • 26
  • 218
  • 353
1 2
3
48 49