-2

I am unable to run .jar archives using Java 10 or Java 11 (they exit with NoClassDefFoundError). Likewise, I am also unable to import .jar archives into a Java Project; they appear in the Classpath, but Eclipse says that the import cannot be resolved. When I downgraded to Java 8, I was able to run .jar archives just fine and they would also be recognized in any Java Project that imported them.

For example:

I am importing mongo-java-driver-3.8.2 into a Java Project on Eclipse Photon. I add the .jar to the Project's Classpath (Project -> Properties -> Java Build Path). However, Eclipse outputs The import com.mongodb cannot be resolved, as seen in the picture below:

enter image description here

Lazy Wolf
  • 97
  • 3
  • 10
  • 1
    You've got to understand the fact that classpath is not alone now, its accompanied by something called modulepath and that your `jars` have to be present in either of these. Sounds like from your setup ideally Eclipse should be taking care of that, which in few other questions seems to be working fine. That said, please check the compatibility of the version of Eclipse you're using and the jar(libraries) you're using further with Java10/11. – Naman Oct 16 '18 at 12:34
  • 1
    Please read "How to create a [mcve]". Then use the [edit] link to improve your question (do not add more information via comments). Otherwise we are not able to answer your question and help you. – GhostCat Oct 16 '18 at 12:34
  • I would guess that you see effects of modulepath vs. classpath. But your question reads like a guy calling his garage "my car is making strange noises. now tell me how to fix that". We can't, given the amount of information we got so far. – GhostCat Oct 16 '18 at 12:35
  • Do you use JPMS (does the default package contain a `module-info.java` file)? – howlger Oct 16 '18 at 13:02
  • It does contain that file. @GhostCat Sorry. I have edited my original question to include an example. – Lazy Wolf Oct 16 '18 at 13:04
  • Does removing `module-info.java` fix your issue? Or adding the line `requires mongo.java.driver;`? – howlger Oct 16 '18 at 13:13

1 Answers1

2

If the default package contains a module-info.java file, you are using the Java Platform Module System (JPMS) and you have two options:

  • Delete module-info.java to not use JPMS and to use the classpath as in Java 8
  • In module-info.java add the line requires mongo.java.driver; to add the module mongo.java.driver (which exports the package com.mongodb) to the modulepath (since Java 9 you can use either the classpath without a module-info.java file or the modulepath with the module-info.java file)
howlger
  • 31,050
  • 11
  • 59
  • 99