Questions tagged [module-info]

Used for module-info.class related queries used for module declaration in Java since its Java 9 release. This would mostly be coupled with java-9 or above tag.

The State of the Module System defines module declarations as:

A module’s self-description is expressed in its module declaration, a new construct of the Java programming language.

The simplest possible module declaration merely specifies the name of its module:

module com.foo.bar { }

The source code for a module declaration is, by convention, placed in a file named module-info.java at the root of the module’s source-file hierarchy. The source files for the com.foo.bar module, e.g., might include:

module-info.java
com/foo/bar/alpha/AlphaFactory.java
com/foo/bar/alpha/Alpha.java
...

A module’s declaration does not include a version string, nor constraints upon the version strings of the modules upon which it depends. This is intentional: It is not a goal of the module system to solve the version-selection problem, which is best left to build tools and container applications.

Module declarations are part of the Java programming language, rather than a language or notation of their own, for several reasons

157 questions
6
votes
2 answers

How to expand the module path at runtime

I like services. I also like the module system. Unfortunately for me, before I used Java 9 I got in the habit of getting service providers from jars loaded at runtime via URLClassLoader, something like this (I'll use Java 10's var for brevity): var…
Anonymous
  • 491
  • 2
  • 12
6
votes
2 answers

Is `sun.awt.image` package deprecated?

I wanted to use some codes that using sun.awt.image.PNGImageDecoder in my project. The problem is source code is based on Java 8 and my project using JDK 9+ (11). So I got this error: Package 'sun.awt.image' is declared in module 'java.desktop',…
Mir-Ismaili
  • 13,974
  • 8
  • 82
  • 100
5
votes
1 answer

VM crash with maven-surefire-plugin having module-info.java

Initially I had one unique module-info in the next folder: src/main/java/module-info.java. I was able to run the tests successfully. Now I need to overwrite the module-info because I need to add some changes that are relevant only for the test. The…
ravenskater
  • 702
  • 1
  • 7
  • 20
5
votes
0 answers

How do I write module-info requires statement from GAV coordinates of a non-modular dependency?

I am converting a legacy java app to a modular one. It is a Gradle project, and the dependencies look like this: dependencies { implementation 'org.jopendocument:jOpenDocument:1.3' implementation 'xom:xom:1.3.2' } In the App class, my…
5
votes
1 answer

When this error occurs Error:(1, 1) java: module JavaFX reads package java.awt from both java.desktop and java.datatransfer

project name-JavaFX module-info.java module JavaFX { requires javafx.fxml; requires javafx.controls; requires java.desktop; opens sample; } Controller.java package sample; import javafx.fxml.FXML; import java.awt.Desktop; import…
vikalp rusia
  • 95
  • 1
  • 11
5
votes
2 answers

Java 11 : Execution default-compile of goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile failed.: NullPointerException

I am upgrading my project from java 8 to java 11. I'm able to build and deploy it with java11, spring 5 dependencies but when I am adding module-info.java into my project I am getting below error while build : [ERROR] Failed to execute goal…
Pukhraj soni
  • 1,832
  • 2
  • 17
  • 11
5
votes
1 answer

How do Java Module directives impact reflection access into a module?

According to https://www.oracle.com/corporate/features/understanding-java-9-modules.html, the Java Module system introduces the following directives: exports, exports ... to uses provides ... with open, opens, opens ... to What (if any) impact…
Gili
  • 86,244
  • 97
  • 390
  • 689
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
1 answer

How to have the java8 code that uses Unsafe working on jdk8 and jdk9?

I am using sun.misc.Unsafe in my Java8 codebase. This does not work on Java9. I would like to have the fix for Java9, but with the same codebase that runs on Java8. If I put module-info.java, it will not work, as my codebase is Java8. What to do?
igr
  • 10,199
  • 13
  • 65
  • 111
5
votes
1 answer

Unable to use classes from unnamed modules after creating module-info.java

I'm trying to migrate an old java project to java 9, and preferably try out the new module-info.java functionalities. The project uses maven dependencies, and as far as I can tell, those migrate .jar's as unnamed modules. The project itself runs…
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
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
4
votes
0 answers

From shading to modules: How to avoid version conflicts?

My context is that I have written a java library that does something "useful" and this library is (as is common for libraries) to be used in other applications. Among other things my library uses Antlr 4 to generate part of the code. Key thing here…
4
votes
1 answer

stuck on javafx.graphics does not export com.sun.javafx.sg.prism to unnamed module

I've been stuck on this error now for a few days. I've googled the heck out it and tried at least a dozen different proposed solutions in various forms... My project runs fine, UNTIL I attempt to use a specific library called MonacoFX, which,…
Michael Sims
  • 2,360
  • 1
  • 16
  • 29
4
votes
0 answers

What does "at the discretion of the host system" mean in the context of module resolution?

In two places in the package documentation for the java.lang.module package, the phrase "at the discretion of the host system" occurs. I feel like it is trying to tell me something important, and I understand the English, but I fail to see what that…
Laird Nelson
  • 15,321
  • 19
  • 73
  • 127
1 2
3
10 11