0

I have a library compiled with jdk7. Now, I want to import it in a jdk9 module.

We are using maven to manage the dependencies, but after adding the library into the dependency. We still can’t find the classes in the library. But if we remove the module-info.java, everything is ok.

Here is the problem: we have to deliver a jdk9 module, but we have a lot of jdk7 library dependencies. Is it possible? If it is, how? If it isn’t, is there any alternative way?

Naman
  • 27,789
  • 26
  • 218
  • 353
Meilun Sheng
  • 129
  • 1
  • 1
  • 7
  • You should be able to include them as a dependency and include their ***automatic module*** name in the module-info.java. What error do you face if you proceed this way? Note:- Please make sure you're using maven plugin versions compatible to Java9. – Naman Mar 22 '18 at 02:20
  • @nullpointer i use maven-jar-plugin to add Automatic-Module-Name=com.xxx.ps for jdk7 libraries, and when compiling the jdk9 module, it says that the package is declared in the unnamed module, but the jdk9 module doesn’t read it. – Meilun Sheng Mar 22 '18 at 02:25
  • What's the exact problem? If you are shipping a library compiled on 1.7, I guess it will be able to run on 1.7+ including 1.9. Perhaps, posting the exact error will make the question clearer. – tryingToLearn Mar 22 '18 at 05:19

1 Answers1

0

package is declared in the unnamed module, but the jdk9 module doesn’t read it it says that your explicit module (which contains module-info) tries to access something in classpath, but in jdk9 it`s forbidden. Instead you can move your jar from classpath to module-path and make it automatic module which can refer both classpath and explicit modules

  • Yes, if I copy the jar into a directory, and add the directory as a module path, I can require the module correctly. It seems that the maven compiler plugin didn’t add module path correctly, I am trying finding why. – Meilun Sheng Apr 10 '18 at 10:38