Trying to convert a Java 8 project to use modules in Java 11.
We created the module.info file in Eclipse and everything is compiling fine within Eclipse. But we’re having problems setting up the build which uses ANT (v 1.10.12).
Our code being compiled will be in a module, but it depends on non-modular jar files so it needs to create automatic modules for those jars from my understanding.
But the build keeps failing.
The module.info file looks something like the following where it requires externalclient which should be an automatic module created from non-module jar externalclient.jar
`module project.ourmod {
exports com.projectname.client;
requires externalclient;
}`
Our source code resides in productpath/src/main/java
And the externalclient.jar resides in projectpath/lib/main/java
The .classpath that Eclipse creates (and compiles just fine) looks like
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="lib" path="lib/main/java/externalclient.jar">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>
The ANT build target to compile uses javac which we tried to modify to handle building now as a module and looks like the following.
<path id="classpath.junit">
<pathelement location=“projectpath/lib/main/java/externalclient.jar"/>
</path>
<echo>Compiling project client code ...</echo>
<tpcr.javac
ldestdir="projectpath/bin"
srcdir=“projectpath/src/main/java"
modulepath="${classpath.junit}"
listfiles="${compiler.verbose}"
encoding="UTF-8"
optimize="${compiler.optimize}"
debug="${compiler.debug}"
debuglevel="${compiler.debuglevel}">
<include name="com/projectname/client/**”/>
<compilerarg line="--add-modules externalclient"/>
</tpcr.javac>
We tried using but it wasn’t finding the java files to compile. Using srcdir it does see the files however when it tries to compile them we get the following error.
[echo] Compiling project client code ...
[tpcr.javac] Compiling 278 source files to projectpath/bin
[tpcr.javac] projectpath/src/main/java/module-info.java:28: error: module not found: externalclient
[tpcr.javac] requires externalclient;
[tpcr.javac] ^
[tpcr.javac] error: cannot access module-info
[tpcr.javac] cannot resolve modules
[tpcr.javac] 1 errors
We thought that specifying the path holding the externaclient.jar file in would handle making it an automatic module, but doesn’t seem to be working. Seems like we’re still missing something.
NOTE: Renamed the files and directories…so might be some typos…just trying to get the main setup across.