Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does JPMS support module version?

I thought that JPMS doesn't support module version. However, when I do java --list-modules I have the following output:

java.activation@9
java.base@9
java.compiler@9
java.corba@9
java.datatransfer@9
java.desktop@9
java.instrument@9 
....

So, I can't understand what this @9 is. Is this version or what? If JPMS supports module version, can I set in module-info of module A, that module A requires module B of certain version?

like image 472
Pavel_K Avatar asked Jan 08 '18 13:01

Pavel_K


People also ask

What are modules in Java 9?

Defining the Java 9 module. A module is a collection of code, data, and resources. It is a set of related packages and types (classes, abstract classes, interfaces, and more) with code, data files, and some static resources.

What is module system?

A module is a distinct assembly of components that can be easily added, removed or replaced in a larger system. Generally, a module is not functional on its own. In computer hardware, a module is a component that is designed for easy replacement.

How do you call a module in Java?

To set up a module, we need to put a special file at the root of our packages named module-info. java. This file is known as the module descriptor and contains all of the data needed to build and use our new module. We start the module declaration with the module keyword, and we follow that with the name of the module.

What are Java modules used for?

A Java module is a set of packages that declares which of them form an API accessible to other modules and which are internal and encapsulated — similar to how a class defines the visibility of its members. A module also declares what other modules it requires for its operation.


2 Answers

I can't understand what this @9 is. Is this version or what?

Yes, it is the version of the module.

If JPMS supports module version, can I set in module-info of module A, that module A requires module B of certain version?

No, you cannot refer a specific version of a module in another module's declaration. I believe this was always clearly mentioned in The State of the Module System#Module Declarations

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 as 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.

like image 195
Naman Avatar answered Oct 03 '22 17:10

Naman


To shed more light on the existing @9 information:

JVMS 9 includes a field module_version_index in the Module_attribute structure, i.e., the class file format supports storing a version string of a module, even a requires_version_index has been defined, but I am not aware of any specification that relates to evaluating this version, rendering this data purely informative at this point.

More information about the current status (as of Java 9 GA) regarding module versions can be found in the Issue Summary. The format of versions is defined in ModuleDescriptor.Version API.

like image 29
Stephan Herrmann Avatar answered Oct 03 '22 17:10

Stephan Herrmann