On 11/07/2017 12:56 PM, Stephan Herrmann wrote:
On 07.11.2017 21:43, Alan Bateman wrote:
On 07/11/2017 18:56, Stephan Herrmann wrote:
I recently noticed that compilers start to ignore -classpath as soon
as module-info (.java or .class) is found during the compile.
(Incidentally, javac and Eclipse compiler agree in this).
Using a trivial test class this works:
$ javac -classpath junit4.jar -d bin/ src/pkg/TestJUnit4.java
This doesn't (cannot resolve any types from junit4.jar):
$ javac -classpath junit4.jar -d bin/ src/pkg/TestJUnit4.java
src/module-info.java
The module you are compiling doesn't read the unnamed module. You
can't write "requires $CLASSPATH" for example.
If you add `--add-reads <module>=ALL-UNNAMED` to the command line
then it should compile.
-Alan
Thanks, Alan, that would work.
But that is not what I meant when referring to JEP 261.
In JEP 261 I see (under "Single-module mode"):
"It is possible to put arbitrary classes and JAR files on the class
path in this mode,
but that is not recommended since it amounts to treating those
classes and JAR files as
part of the module being compiled."
Doesn't this say, my above command line treats junit4.jar as part of
the current module,
*not* as an unnamed module?
Is everything referenced via -classpath definitely treated as an
unnamed module?
Independent of single-/multi-module modes?
Stephan
Stephan,
I think you have identified some outdated text that needs to be fixed.
The text was correct at one point, when the distinction between "single
module mode"
and "multi-module mode" was a bigger deal.
These days, the primary distinction is between "classpath (legacy) mode"
(no modules being compiled)
and "module mode" (one or more modules being compiled.)
Here's how javac treats these modes:
In classpath (legacy) mode ...
* the sourcepath, classpath and output directory behave as previously,
such as in JDK 8.
In module mode ...
* all classes on the classpath (-classpath) are treated as part of the
unnamed module.
* if you are just compiling a single module, you may either put the
source for that module
on the source path (-sourcepath) or in a directory on the module source
path (--module-source-path).
* if you are compiling multiple modules, they must be in separate
directories on the
module source path (--module-source-path).
* javac will implicitly look for previously compiled classes in the
output directory (-d).
(This is in contrast to the usage in classpath/legacy mode, where it has
always been common practice
to explicitly put the output directory on the classpath as well.)
-- Jon