Reputation: 11739
There is a mechanism to convert regular jar into an automatic module starting from java-9, by simple placing it onto modulepath
instead of classpath
. An automatic module has the following properties:
An automatic module is a named module that is defined implicitly, since it does not have a module declaration. Every package in an automatic module is, therefore, considered to be exported even if it might actually be intended only for internal use.
So all packages inside an automatic module are available. But if we inspect an automatic module with --describe-module
directive there is no exports
section in the output.
For example an automatic module main
jar --file main.jar --describe-module
com.foo jar:file:///.../code/module/main.jar/!module-info.class
requires java.base mandated
contains com.foo
Why is there no exports
section if package com.foo
is considered to be exported anyway? I find this a bit confusing: --describe-module
suggests that there are no exported packages, but at the same time, main
is an automatic module so everything is exported implicitly.
Upvotes: 3
Views: 945
Reputation: 31868
I believe, the command line option --describe-module
within the jar
tool is just to describe what the jar file is about, if its an explicit module the complete descriptor is shared whie for automatic module just the name is depicted.
Quoting from the command jar --help
Print the module descriptor, or automatic module name
On the other hand, if you try using jdeps
for generating module-info.java
of an automatic module given a jar file, you can notice that such packages exports are actually present in the module declaration. Say for example:
jdeps -verbose:class --generate-module-info ../Desktop ~/.m2/repository/org/apache/commons/commons-lang3/3.8.1/commons-lang3-3.8.1.jar
writes to .../Desktop/org.apache.commons.lang3/module-info.java
the following
module org.apache.commons.lang3 {
requires transitive java.desktop;
exports org.apache.commons.lang3;
exports org.apache.commons.lang3.arch;
exports org.apache.commons.lang3.builder;
exports org.apache.commons.lang3.concurrent;
exports org.apache.commons.lang3.event;
exports org.apache.commons.lang3.exception;
exports org.apache.commons.lang3.math;
exports org.apache.commons.lang3.mutable;
exports org.apache.commons.lang3.reflect;
exports org.apache.commons.lang3.text;
exports org.apache.commons.lang3.text.translate;
exports org.apache.commons.lang3.time;
exports org.apache.commons.lang3.tuple;
}
Upvotes: 3