MANIFEST.MF has nothing to do with dependencies. You need to create a module-info.java file and declare your dependency there:
module <module-name> { requires <dependency>; ... }
However, if you compile module-info.java and just put module-info.class in the JAR, Java 8 will not be able to run it. So what to do? In Java 9: ββmulti-disk JAR files have a new feature ( JEP 238 ). The idea is that you can put Java 9 class files in a special directory ( META-INF/version/9/ ) and Java 9 will handle them correctly (while Java 8 ignores them).
So these are the steps you must follow:
- Compile all classes except
module-info.java using javac --release 8 - Compile
module-info.java using javac --release 9 . - Create a JAR file so that it has the following structure:
JAR root - A.class - B.class - C.class ... - META-INF - versions - 9 - module-info.class
As a result, the JAR must be compatible with Java 8 and Java 9.
UPDATE:
It turns out there is no need to insert module-info.class into the META-INF folder. You can just put it in the root of the JAR. This will have the same effect.
Zhekakozlov
source share