Issue
I'm converting a simple application to java modules. I also need to make this application self contained with it's own custom JRE. My application relies on multiple existing library jars that I am also converting to modular jars. To build a custom JRE I know that all code must be in modules. (You can't reference non-modular jars. I found that out the hard way).
The problem is when I'm compiling the modules-info.java for one of the library jars that depends on another library jar (that I have already converted to modular). It returns "error: module not found:jersey.core"
I've already updated one of the library jars by manually creating the module-info.java, compiling it and then updating the existing jar.
1). The file I created.
module jersey.core {
exports com.sun.jersey.api.provider.jaxb;
exports com.sun.jersey.api.representation;
exports com.sun.jersey.api.uri;
exports com.sun.jersey.core.header;
exports com.sun.jersey.core.header.reader;
exports com.sun.jersey.core.impl.provider.entity;
exports com.sun.jersey.core.impl.provider.header;
exports com.sun.jersey.core.impl.provider.xml;
exports com.sun.jersey.core.osgi;
exports com.sun.jersey.core.provider;
exports com.sun.jersey.core.provider.jaxb;
exports com.sun.jersey.core.reflection;
exports com.sun.jersey.core.spi.component;
exports com.sun.jersey.core.spi.component.ioc;
exports com.sun.jersey.core.spi.factory;
exports com.sun.jersey.core.spi.scanning;
exports com.sun.jersey.core.spi.scanning.uri;
exports com.sun.jersey.core.util;
exports com.sun.jersey.impl;
exports com.sun.jersey.localization;
exports com.sun.jersey.spi;
exports com.sun.jersey.spi.inject;
exports com.sun.jersey.spi.service;
exports javax.ws.rs;
exports javax.ws.rs.core;
exports javax.ws.rs.ext;
requires java.base;
requires java.desktop;
requires java.logging;
requires java.xml;
}
2). Compiling
"%JDK11_HOME%/bin/javac" --patch-module jersey.core=../originaljars/jersey-core-1.13.jar module-info.java
3). Updating the jar
"%JDK11_HOME%/bin/jar" uf ../modules/jersey-core-1.13.jar -C jersey.core module-info.class
This was successful.
At first I tried creating the jersey.client module-info.java without a "depends on jersey.core". Again, went through the same process of compiling and updating the jar but when I added the jar to my project Eclipse displayed the following error in MyTester.java.
The type javax.ws.rs.core.MediaType cannot be resolved. It is indirectly referenced from required .class files MyTester.java
This was thrown for a line where a WebResource object (comes from jersey.client) calls method webResource.type("application/json") which return a MediaType.
javax.ws.rs.core.MediaType comes from jersey.core. So that lead me to believe jersey.client needs to require jersey.core.
I then decided to update the module-info.java for jersey.client
I added a requires jersey.core.
module jersey.client {
exports com.sun.jersey.api.client;
exports com.sun.jersey.api.client.async;
exports com.sun.jersey.api.client.config;
exports com.sun.jersey.api.client.filter;
exports com.sun.jersey.client.impl;
exports com.sun.jersey.client.impl.async;
exports com.sun.jersey.client.osgi;
exports com.sun.jersey.client.proxy;
exports com.sun.jersey.client.urlconnection;
exports com.sun.ws.rs.ext;
requires java.base;
requires java.logging;
requires jersey.core;
}
But when I try to compile this, I get the following error.
"%JDK11_HOME%/bin/javac" --patch-module jersey.client=../originaljars/jersey-client-1.13.jar module-info.java
module-info.java:15: error: module not found: jersey.core
requires jersey.core;
^
1 error
Figured, the error was literally telling me it can't find the module, so I needed to tell it where my modules were located.
"%JDK11_HOME%/bin/javac" --patch-module jersey.client=../originaljars/jersey-client-1.13.jar module-info.java -p ../modules
module-info.java:15: error: module not found: jersey.core
requires jersey.core;
^
1 error
And then thought maybe I need to also add the module explicitly. But that also didn't work.
"%JDK11_HOME%/bin/javac" --patch-module jersey.client=../originaljars/jersey-client-1.13.jar module-info.java -p ../modules --add-modules jersey.core
module-info.java:15: error: module not found: jersey.core
requires jersey.core;
^
1 error
I'm very new to Java Modules so undoubtedly I'm doing something stupid. Apologies in advance :(
Solution
Ok, so it turns our I did do something stupid.
1). You do have to set the module path to your application modules.
2). You can't use relative links for the path. I updated it to be a full path.
"%JDK11_HOME%/bin/javac" --patch-module jersey.client=../originaljars/jersey-client-1.13.jar module-info.java --module-path "C:{add your full path here}\modules"
Answered By - Aaron
Answer Checked By - Timothy Miller (JavaFixing Admin)