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

Error while trying to compile and run sample module in Java

I'm new to the topic of modules, and I'm following a simple example of how to create, compile and run them. The folder structure of my project is illustrated in the following diagram: First I typed this in a cmd window to compile the…
osfar
  • 401
  • 1
  • 4
  • 23
4
votes
1 answer

Java 11 module-info: how to register an annotation processor

To register a service provider in a Java 11 the following "provides" module-info entry can be used: module com.mycompany.mylib { provides ServiceInterface with ServiceImpl; } With annotation processors this doesn't seem to work, however. (The…
Puce
  • 37,247
  • 13
  • 80
  • 152
4
votes
1 answer

module descriptor file allowed import statements Why?

please anyone explain me module descriptor file allowed import Why? what is the used of import statement in module descriptor file. import java.util.*; module superman { }
Ng Sharma
  • 2,072
  • 8
  • 27
  • 49
4
votes
0 answers

How to generate module-info by Annotation Processor?

I have some codes to generate some services at compiling time by java APT, before java9, I generate java source code by APT, and using Google AutoService to generate service file under META-INF/services folder, now I want to upgrade it to use Java9…
4
votes
1 answer

Best way to use Java module system in an educational setting?

I teach Java programming courses in a college setting. It would make sense to use the latest LTS version (Java 11) in the courses. We teach user interfaces using JavaFX. However, the combination of JavaFX plus the module system creates…
Brad Richards
  • 1,233
  • 3
  • 13
  • 23
4
votes
1 answer

How to add maven dependencies of json to modules in >= Java 9

in java 8 projects you simply add the following dependencys in maven javax.json javax.json-api 1.1
huidube
  • 390
  • 3
  • 15
4
votes
1 answer

Java 9: ServiceLoader doesn't load Test implementation from Test sources (Module)

I'm using Java9 Module system (running on openjdk11) I have migrated from Java8 and the code contained classes that made use of the ServiceLoader mechanism. a unit test for this class which tries to load two test service implementations the…
Gerald Mücke
  • 10,724
  • 2
  • 50
  • 67
4
votes
0 answers

Eclipse 2018-09 doesn't find test classes if module-info.java is present

I have a simple Java 11 project in Eclipse with the following dependencies: dependencies { testImplementation("org.junit.jupiter:junit-jupiter-api:${junit}") testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junit}") } The…
l_mcqueen
  • 55
  • 6
4
votes
1 answer

Is it possible to use SharedSecrets across Java modules?

Given: Modules A and B, where B imports A. Module A exports external.class1. It defines but does not export external.class1.secretProvider, internal.SharedSecrets and internal.class2 (more on these below). Module A uses the SharedSecrets mechanism…
Gili
  • 86,244
  • 97
  • 390
  • 689
4
votes
1 answer

log4j2 configuration file not found with java 9

I had a Java 8 project and my configuration file was in resource folder and everything worked fine. Now I switched to Java 9, added requirement for log4j.api, and configuration file cannot be found anymore. Do I need to add something else in my…
EmberTraveller
  • 355
  • 3
  • 18
4
votes
1 answer

Service interface provided but not exported or used warning in module-info class

Java9 - jdk-9+181 intelliJ - 2017.2.2 built on August 9,2017 The java.management.rmi's module-info.java implementation is somewhat like: module java.management.rmi { ... requires transitive java.management; exports…
Naman
  • 27,789
  • 26
  • 218
  • 353
3
votes
2 answers

Circumvent old java meta-inf / services when using Java modules

I am trying to make a Java FX application showing an SVG-image using the Batik-library, but I'm having issues getting all the components properly imported. After about 5 hours of searching and testing I have finally altered one of the dependencies'…
3
votes
2 answers

module-info not compiled unless package classes are compiled with the same command

I've got a folder called myModule. Inside it, there's another folder called myPackage in which my Main.class exists. Next to myPackage I have my module-info.java which I'd like to compile. First take a look at the folders hierarchy: -- myModule …
Joseph_Marzbani
  • 1,796
  • 4
  • 22
  • 36
3
votes
1 answer

How to make Java class invisible outside its module for other non-modular projects?

Recently I've found out that if a package inside a module contains public interfaces or classes they are being exported automatically and hence unintentionally visible outside the module in case when recipient code is not modularized. Structure of…
diziaq
  • 6,881
  • 16
  • 54
  • 96
3
votes
0 answers

Merge jars for split package using gradle

I created a web application. I am using Gradle. I am new to Gradle and I am trying to migrate one of my projects to Java 9 module system. I moved all the jars to module path instead of the classpath. Here is the snippet of my build.gradle plugins { …
Basit
  • 8,426
  • 46
  • 116
  • 196