I've included these dependencies in my Maven pom.xml:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
I am trying to add this dependency in module-info.java like so:
module io.github.wildcraft.restclient {
requires httpcore; // no compilation problem
requires httpclient; // no compilation problem
requires commons-io; // shows compilation error
}
For commons-io, I receive a compilation error. How can I make this work?
Short Version
Use
requires commons.io
. (In general, see nullpointer's answer how to learn a module's name.)Long Version
Since
commons-io.jar
is not yet modularized, you are creating an automatic module, for which the module system has to come up with a name. The Javadoc ofModuleFinder
describes how that happens:The last two bullets apply to automatic modules that are not prepared for Java 9, e.g. to
commons.io
. This example from the same Javadoc explains what happens in your case:Hence
requires commons.io
should work.Adding to the shorter version of the answer provided by Nicolai. In order to find out the module name of the dependencies(jar) used in your project, you can use the jar tool from command line.
Since these would be understood as an automatic module by the tool, the output would be somewhat like:-