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

Main method doesn't run inside a module

Do I need to run my main method inside a module or outside? I am new in using the modular system of Java. I am trying create a simple program with JavaFX in Java 10, since it is the last version of Java that supports JavaFX. I imported the necessary…
neth07
  • 61
  • 3
5
votes
0 answers

Class not found in Spring when using Java modules and jlink

I'm adding module definitions to Spring Boot to be able to jlink my project. One of the errors I encountered is: Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException:…
Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
5
votes
1 answer

Naming convention for java 9 modules

What's the naming convention for java 9 modules? Let's say my package name is me.jasonyeo.awesome.project, and whenever I create a module-info.java file in IDEA, it would suggest me to name it awesome.project Is that the convention? Or should I name…
Jason Yeo
  • 3,602
  • 3
  • 30
  • 38
5
votes
1 answer

Using Ignite on JDK 9

I am having trouble using Ignite on JDK 9. I have the following minimal testcase: package no.ovstetun.ignite; import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; import org.junit.Test; public class FailingIgniteTest { @Test public…
5
votes
0 answers

How to use --patch-module along with --class-path | javac

How can I use a custom classpath when overriding a native class like java.util.regex.Matcher in a non-modular code base. Basically what I want to do is to use a different class path like --class-path build/custom when patching a class. Because the…
Gayan Weerakutti
  • 11,904
  • 2
  • 71
  • 68
5
votes
1 answer

Securely Export Packages to Java Modules

I was answering this question, where I recommended utilizing exports to syntax to prevent external consumers from accessing code that is intended for internal use between modules. But on further reflection, the only real safety checking that modules…
Ironcache
  • 1,719
  • 21
  • 33
5
votes
1 answer

How is Java 9 running code compiled with Java 8 that is using a non-exported package

I compiled following code using Java-8 compiler: package pack; import sun.util.calendar.CalendarUtils; public class A { public static void main(String[] args) { System.out.println(CalendarUtils.isGregorianLeapYear(2018)); } } I…
my name is GYAN
  • 1,269
  • 13
  • 27
5
votes
1 answer

Unnamed module interaction with named module by ServiceLoader::load

I have a project like this: \---main \---src \---com.foo \---UnnamedStart.java \---api \---src \---com.foo.api \---ApiInterface.java \---module-info.java \---impl \---src …
Andrew Sasha
  • 1,254
  • 1
  • 11
  • 21
5
votes
3 answers

module-info.java does not work with lombok in Java 9

I faced problem during migration our project to Java 9. After I've updated Java 9, I attempt to run project, I faced with compiler errors :- Error:(6, 1) java: package javax.annotation is not visible (package javax.annotation is declared in module…
Andrey
  • 121
  • 2
  • 5
5
votes
1 answer

Java 9 migration javax.annotation

So i try to migrate my project to Java 9 but the process seems not so easy as i thought it would be. I kept getting some errors about invisible packages that i could fix with the following argument in my pom:
5
votes
2 answers

directory layout for Java 9 modules

I've been trying to write a Java 9 module, but no matter what I do, I get the error "package is empty or does not exist". I've tried searching online for the expected directory layout, and tried every variation on directory layout I can think of,…
Antimony
  • 37,781
  • 10
  • 100
  • 107
5
votes
2 answers

What is the difference between ResolvedModule, Module and Observable Module

The documentation for each of these states following: ResolvedModule A module in a graph of resolved modules. ResolvedModule defines the configuration method to get the configuration that the resolved module is in. It defines the reference…
Naman
  • 27,789
  • 26
  • 218
  • 353
5
votes
2 answers

How to call a service from module in a new created 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-a has one interface com.mod-a.Service and in its module-info I have: module module-a { exports…
Pavel_K
  • 10,748
  • 13
  • 73
  • 186
5
votes
1 answer

How do I include a java 9 module at runtime?

I have a server kit that I'm trying to test on the java9 JDK (found here, I'm using the 64-bit Linux version), however I'm encountering the following error shortly after startup: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException Caused…
Zim-Zam O'Pootertoot
  • 17,888
  • 4
  • 41
  • 69
4
votes
2 answers

How to inspect jvm module contents from the command line?

I would like to inspect the contents of a resource file of a java module of my locally installed jvm from the command line. Based on a question about mime type support in a jvm I would like to see the contents of…
SpaceTrucker
  • 13,377
  • 6
  • 60
  • 99