1

I'm using JDK 11 on Windows. I realized a modular JAR file, Uti.jar (into the directory dirLib), containing some classes in a single package, say pkg.

Then I realized a simple client, say app.Maine, not a module, with a main method (a console app), which uses a class contained in Uti.jar, say pkg.MyClass.

I'm able to execute the console app with the command:

java -classpath dirLib/Uti.jar;. app.Maine

It works.

But I've problems when trying to use a JMOD file instead of Uti.jar. I built Uti.jmod by using the command

jmod create --class-path pkg dirLib/Uti.jmod

It seems containing the same classes as Uti.jar, but the command

java -classpath dirLib/Uti.jmod;. app.Maine

gives an error, NoClassDefFoundError pkg/MyClass.

Where am I mistaking ?

Thanks in advance

Naman
  • 23,555
  • 22
  • 173
  • 290
  • Could you try using the `--module-path` flag instead of `classpath` ?? – Naman Dec 15 '18 at 19:33
  • JMOD files are not something that most developers will ever see. They are for cases where you are developing a library as a module and it contains native libraries, launchers, or other configuration files. JMOD files are consumed by the jlink tool. When jilnk is creating a run-time image then it can find JMOD files that are on the module path. So no support for putting JMOD files on the class path or module path when you are using the `java` launcher. – Alan Bateman Dec 16 '18 at 07:30
  • Hi Alan. If I'm correctly understand your answer, usual application development must be performed by means of JARs. In fact, I don't plan to create a run-time image every time I work. Isn't it a quite severe restriction ? – Virgilio Ravagli Dec 17 '18 at 10:42
  • If you aren't using the `jlink` tool then there shouldn't be any reason to create JMOD files. For your library or application then you should be able to package it as a JAR (or modular JAR if you are developing a module). – Alan Bateman Dec 17 '18 at 11:04
  • Okay, thank you Alan, you're very neat, unfortunately I was misleaded by people who said modularity is the new Java programming paradigm, but now I understand it's not... – Virgilio Ravagli Dec 18 '18 at 09:27

0 Answers0