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
286
votes
11 answers

Replacements for deprecated JPMS modules with Java EE APIs

Java 9 deprecated six modules that contain Java EE APIs and they are going to be removed soon: java.activation with javax.activation package java.corba with javax.activity, javax.rmi, javax.rmi.CORBA, and org.omg.* packages java.transaction with…
Nicolai Parlog
  • 47,972
  • 24
  • 125
  • 255
239
votes
4 answers

What is an illegal reflective access?

There are a lot of questions about illegal reflective access in Java 9. I have found plenty of discussion about working around the error messages, but I would love to know what an illegal reflective access actually is. So my question is: What…
Tschallacka
  • 27,901
  • 14
  • 88
  • 133
212
votes
21 answers

How to solve InaccessibleObjectException ("Unable to make {member} accessible: module {A} does not 'opens {package}' to {B}") on Java 9?

This exception occurs in a wide variety of scenarios when running an application on Java 9. Certain libraries and frameworks (Spring, Hibernate, JAXB) are particularly prone to it. Here's an example from…
Nicolai Parlog
  • 47,972
  • 24
  • 125
  • 255
132
votes
5 answers

Cannot be cast to class - they are in unnamed module of loader 'app'

I'm trying to create a bean from sources that were generated by wsdl2java. Every time I try to run my Spring Boot app, I get the following error: Caused by: java.lang.ClassCastException: class org.apache.cxf.endpoint.ClientImpl cannot be cast to…
Cisco
  • 20,972
  • 5
  • 38
  • 60
107
votes
7 answers

What's the difference between requires and requires transitive statements in Java 9?

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

What's the difference between --add-exports and --add-opens in Java 9?

Java 9 (jdk-9+170) does not allow by default an application to see all classes from the JDK, unlike all previous versions of Java, due to the new module system. To workaround this, the java command line offers a new argument --add-exports which…
70
votes
8 answers

Illegal reflective access by org.springframework.cglib.core.ReflectUtils$1

My JDK 9+181 Spring Boot 2.0.0.BUILD-SNAPSHOT CLI application displays this warning on startup: WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils$1…
Jan Nielsen
  • 10,892
  • 14
  • 65
  • 119
68
votes
1 answer

In Eclipse, what is the difference between modulepath and classpath?

In Eclipse, what is the difference between modulepath and classpath, and which one should I use to add a JAR file in the lib folder? And why does the JRE System Library appear in modulepath?
Invariance
  • 1,027
  • 1
  • 7
  • 15
64
votes
6 answers

Java 9 + maven + junit: does test code need module-info.java of its own and where to put it?

Let's say I have a Java project using Maven 3 and junit. There are src/main/java and src/test/java directories which contain main sources and test sources, respectively (everything is standard). Now I want to migrate the project to Java 9.…
Roman Puchkovskiy
  • 11,415
  • 5
  • 36
  • 72
59
votes
4 answers

Is there a replacement library for CORBA in JDK 11

JDK-11 will remove a lot of older parts of the JDK (JEP-320). For some of them (e.g. JAXB) functionality will be provided as regular library. You simply add another dependency and everything works fine again. But not so for CORBA, because There is…
rli
  • 1,745
  • 1
  • 14
  • 25
58
votes
9 answers

JDK9: An illegal reflective access operation has occurred. org.python.core.PySystemState

I'm trying to run DMelt programs (http://jwork.org/dmelt/) program using Java9 (JDK9), and it gives me errors such as: WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by org.python.core.PySystemState…
IraS
  • 729
  • 1
  • 5
  • 6
56
votes
4 answers

What is an automatic module?

Automatic modules are mentioned many times on stackoverflow but I couldn't find a complete, succinct and self-sufficient definition of an automatic module. So, what is an automatic module? Does it export all packages? Does it open all packages? Does…
ZhekaKozlov
  • 36,558
  • 20
  • 126
  • 155
51
votes
4 answers

findResource("") returning null when module-info.java is present, why is that?

I'm debugging why in the presence of module-info.java in my Spring Boot application, spring-orm throws an exception during start up time. This is the exception: org.springframework.beans.factory.BeanCreationException: Error creating bean with name…
Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
46
votes
1 answer

how to pass --add-opens JDK module configuration to maven test

I'm upgrading java version in our production code from java 8 to java 11. I have to add the below JDK module configuration in the application java start command due to usage of third party libraries like flume, zookeeper etc. --add-opens…
41
votes
2 answers

How should I name my Java 9 module?

Suppose I have a library with groupId = org.abc and artifactId = myLibrary. What is the recommended name for the module name: myLibrary or org.abc.myLibrary? Is there any official guide for a naming scheme?
ZhekaKozlov
  • 36,558
  • 20
  • 126
  • 155
1
2 3
48 49