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

What is an open module in Java 9 and how do I use it?

What is the difference between a module with the open keyword before it and without it? For instance: open module foo { } module foo { }
user8693774
  • 403
  • 1
  • 4
  • 5
33
votes
3 answers

What is the difference between modules and JAR files?

I am learning about Java 9 from What's New in Java9 and one of the hot topics in the discussion is The Modular JDK. Are JAR files modules? How is a module different from a JAR file?
Neeraj Jain
  • 7,643
  • 6
  • 34
  • 62
32
votes
2 answers

Create Java runtime image on one platform for another using Jlink

I created runtime image using jlink on my Linux machine. And I see linux folder under the include folder. Does it mean that I can use this runtime image only for Linux platform? If yes, are there any ways to create runtime images on one platform for…
31
votes
3 answers

Package conflicts with automatic modules in Java 9

With Java 9 on the close horizon I thought it would be a good learning exercise to port some of my projects over to Java 9. In one of my projects I have dependencies for rxjava and rxjavafx dependencies { compile 'io.reactivex:rxjava:1.2.6' …
flakes
  • 21,558
  • 8
  • 41
  • 88
28
votes
14 answers

Error occurred during initialization of boot layer FindException: Module not found

Executing a simple "Hello World" program using Java 9 results in the following error message: Error occurred during initialization of boot layer java.lang.module.FindException: Module com.pantech.myModule not found The command line that I…
D. Pante
  • 321
  • 1
  • 3
  • 6
27
votes
3 answers

List modules in jar file

I've created what I'm pretty sure is a modular jar file. But if possible, I'd like to double check. Given a jar file, is there a way to determine what modules the compiler would find within it?
PopKernel
  • 4,110
  • 5
  • 29
  • 51
27
votes
2 answers

How to get access to javax.annotation.Resource at run time in Java 9

I have a test: public class ResourceTest { @Test public void test() throws ClassNotFoundException { Class.forName("javax.annotation.Resource"); } } It tries to access javax.annotation.Resource. In java 8 it worked, but in java 9…
Roman Puchkovskiy
  • 11,415
  • 5
  • 36
  • 72
27
votes
6 answers

How to extract the file jre-9/lib/modules?

In JRE-9/lib directory (at least on Windows), there is a new file called modules whose size is about 107 MB. Is it possible to extract that file or maybe list java modules within it? I can see that a new tool called jmod is available at…
Eng.Fouad
  • 115,165
  • 71
  • 313
  • 417
26
votes
2 answers

What's the difference between requires and requires static in module declaration

What's the difference between requires and requires static module statements in module declaration? For example: module bar { requires java.compiler; requires static java.base; }
Michał Szewczyk
  • 7,540
  • 8
  • 35
  • 47
25
votes
1 answer

How does the Javadoc deal with the visibility of modules in Java 9?

The Javadoc tool generates documentation based on the accessibility modifier. By default, it document all public and protected classes, fields and methods. This can be changed with the following options: -public Shows only public classes and…
user1803551
  • 12,965
  • 5
  • 47
  • 74
24
votes
3 answers

How to inject module declaration into JAR?

Suppose I have some library lib.jar for which I do not have the source code (or it is written in some non-Java language which is unaware of modules yet). lib.jar does not have module-info.class and I do not want to use it as an automatic module, so…
ZhekaKozlov
  • 36,558
  • 20
  • 126
  • 155
24
votes
2 answers

Scanning classpath/modulepath in runtime in Java 9

I can't seem to find any info on whether scanning all available classes (for interfaces, annotations etc) is still possible in runtime, the way Spring, Reflections and many other frameworks and libraries currently do, in the face of Jigsaw related…
kaqqao
  • 12,984
  • 10
  • 64
  • 118
22
votes
2 answers

How to add "requires" for artifact having "-"(hyphen) in its name

I've included these dependencies in my Maven pom.xml: org.apache.httpcomponents httpclient ${httpclient.version}
schoolcoder
  • 1,546
  • 3
  • 15
  • 31
22
votes
1 answer

Modules A and B export package some.package to module C in Java 9

I have three modules module-a, module-b and module-c. When I run my application I get the following: Error occurred during initialization of boot layer java.lang.module.ResolutionException: Modules module-a and module-b export package…
Pavel_K
  • 10,748
  • 13
  • 73
  • 186
22
votes
1 answer

cannot compile Java 9 module with --patch-module in IntelliJ IDEA 2017.2.1

I am trying to acquaint myself with Java 9 modules and how to define them in IntelliJ. Among other things, I want to solve a split package problem using the --patch-module compiler/JVM flag and I don't know how to make it work in IntelliJ. I am…
1
2
3
48 49