Java/OpenJDK : How to add JAR to classpath

Java/OpenJDK : How to add JAR to classpath … here is a solution to the problem.

Java/OpenJDK : How to add JAR to classpath

I ran a 3rd-party jar file on the command line like this (no UI):

 /usr/bin/java -jar exchange-sync.jar

After my release (Debian Buster) was upgraded to the latest OpenJDK 11, this command no longer works. That’s what I get now:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/ws/http/HTTPException
        at com.zerodes.exchangesync.sync.SyncCalendarsImpl.generatePairs(
        at com.zerodes.exchangesync.sync.SyncCalendarsImpl.syncAll(
        at com.zerodes.exchangesync.App.main(
Caused by: java.lang.ClassNotFoundException:
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(
        at java.base/java.lang.ClassLoader.loadClass(


already know that I now need to install the jaxws-api Debian package, which provides the missing classes in /usr/share/java/jaxws-api.jar.

Which java command line do I need in order to include classes from installed jar files? I’ve tried it, but I’m getting the same error :

/usr/bin/java -cp /usr/share/java/jaxws-api.jar -jar exchange-sync.jar

By the way: I’m a Java noob and I don’t want to mess around with the recompile thing. I’m also sure resides in jaxws-api.jar because I browsed that JAR file with vim and was in it


Well, I finally figured it out myself. This is how to correctly add the modules that JAR expects to exist:

/usr/bin/java --module-path /usr/share/java/jaxws-api.jar --add-modules jaxws.api -jar exchange-sync.jar

So it really has nothing to do with the classpath, it’s just about adding modules.

Related Problems and Solutions