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

Is it possible to import two jars with same packages?

I'm migrating project from Java 8 to Java 11, and modularity introduced in java 9 is giving me a headache. Couple jars have same packages, but different classes. This is giving me error module SomeModule reads package my.package from both ModuleA…
user902383
  • 8,420
  • 8
  • 43
  • 63
7
votes
3 answers

Error: Main.class found in top-level directory (unnamed package not allowed in module)

Trying to update an application to Java 11 and after sorting through hell with modules I thought I had got rid of all the red errors and now I'm getting this one I've never seen before: Looking around I've seen people suggest it is possible to do…
AlwaysNeedingHelp
  • 1,851
  • 3
  • 21
  • 29
7
votes
1 answer

java 10 gradle project : automatic module not found

I created a java 10 project with intelliJ, using gradle. I copied some stuff into it (some "AppFx" class using the library guava and javaFx, and a personal build.gradle file). I also added a module-info.java file in src/main/java with this…
lolveley
  • 1,659
  • 2
  • 18
  • 34
7
votes
0 answers

package javax.xml.ws is not visible (Java 10)

Generated code from wsimport fails to compile in Java 10.0.2. We have tried various libraries (including the ones mentioned here). With most suggested libraries, compilation fails with the following missing packages: error: package javax.xml.ws is…
G. Miller
  • 79
  • 1
  • 6
7
votes
2 answers

Can I exclude an exported package from a Java module?

Modules jta and java.sql export package javax.transaction.xa to module dom4j As you can see, both modules jta and java.sql export the same package, javax.transaction.xa. However, the package in jta has classes that I require that are not present…
Jacob G.
  • 28,856
  • 5
  • 62
  • 116
7
votes
1 answer

Inspect --module-path value at runtime

Is there any way to get list of directories which are included in module-path with use of -p or --module-path arguments at runtime similar to how I whold get all classpath directories using System.getProperty("java.class.path")?
Artem Petrov
  • 772
  • 4
  • 17
7
votes
1 answer

List the modules resolved during the application startup

How can one get to know of the list of modules that have been resolved while the application has been started so as to figure out what all service providers are accessible from the root module.
Naman
  • 27,789
  • 26
  • 218
  • 353
7
votes
1 answer

Load class from exploded module using custom classloader

I have been playing around with simple custom classloaders in Java, and so far everything works as expected for non-module related classes. However, I can't seem to find any way to load a class from a module using my classloader, even though the…
7
votes
1 answer

Running Java 9 module using Log4j2 2.10.0

I am trying to run a Java 9 module I've created which uses Log4j2 2.10.0. The problem I'm running into is that I get a java.lang.NoClassDefFoundError: Could not initialize class org.apache.logging.log4j.util.PropertiesUtil when doing a…
ccjohn
  • 71
  • 1
  • 4
7
votes
2 answers

java application not working with java9 and eclipse

I am trying to create a HelloWorld module of Java9 following steps were given below. File>New>Java Project Right-click project(i.e. com.hello)>New>Source Folder>enter source folder name(.e. com.hello) Right click Source Folder(i.e.…
7
votes
2 answers

How to get ResourceBundle from another Module in Java 9?

I have two modules: module-a and module-b. Module-a has properties file (com/foo/texts_en.properties). Module-a exports com.foo package. In module-b I want to get this resource. For this I do the following in module-b: Module moduleA =…
Pavel_K
  • 10,748
  • 13
  • 73
  • 186
7
votes
1 answer

Module javafx.controls not found in Java 9

I have two JPMS module in two files: modulea.jar and moduleb.jar. Modulea requires javafx.controls module. I need to use these modules in new layer, so I do: ModuleFinder finder = ModuleFinder.of(modAPath, modBPath); ModuleLayer parent =…
Pavel_K
  • 10,748
  • 13
  • 73
  • 186
7
votes
2 answers

How to remove module layer in Java 9?

I have three modules: module-a, module-b, module-c. Module-a and module-b are in boot layer. Layer for module-c I create myself. Module-c has JPMS implementation of the service which interface is in module-a. This is the way I create layer with…
Pavel_K
  • 10,748
  • 13
  • 73
  • 186
7
votes
1 answer

java 9: JLink created invalid images - missing module executable script

I am creating a sample application with 3 modules user, dept and account. In my user module, I have a main class and compile my modules with the following command: javac -d target --module-source-path src $(find -name "*.java") After compiling,…
Harmeet Singh Taara
  • 6,483
  • 20
  • 73
  • 126
6
votes
1 answer

Why doesn't the runtime image (assembled by jlink) for my JavaFX application launch and work correctly?

I have a simple JavaFX web browser that is a module. The directory structure of the module is: webBrowser webBrowser/module-info.java webBrowser/webbrowser webBrowser/webbrowser/WebBrowser.java Here is the code to module-info.java module webBrowser…
ktm5124
  • 11,861
  • 21
  • 74
  • 119