[solved] java.lang.NoClassDefFoundError: org/jsoup/Jsoup

I have been using Eclipse to start work on a binding which will be making use of Jsoup.

I have created a lib directory in the project where I placed the jsoup-1.11.2.jar file and have added it to the build path under Libraries, Add JARs.
on my Discovery.java I have an import org.jsoup.Jsoup; which the ide is happy with (doesn’t throw an error that it can’t find the class etc.

Although when I try and test I get the following exception thrown:

2018-01-04 19:40:31.252 [WARN ] [e.jetty.servlet.ServletHandler:624  ] - javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: org/jsoup/Jsoup
	at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:489)
	at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:427)
	at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:388)
	at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:341)
	at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:228)
	at com.eclipsesource.jaxrs.publisher.internal.ServletContainerBridge.service(ServletContainerBridge.java:76)
	at org.eclipse.equinox.http.servlet.internal.HttpServiceRuntimeImpl$LegacyServlet.service(HttpServiceRuntimeImpl.java:1223)
	at org.eclipse.equinox.http.servlet.internal.registration.EndpointRegistration.service(EndpointRegistration.java:148)
	at org.eclipse.equinox.http.servlet.internal.servlet.ResponseStateHandler.processRequest(ResponseStateHandler.java:62)
	at org.eclipse.equinox.http.servlet.internal.context.DispatchTargets.doDispatch(DispatchTargets.java:131)
	at org.eclipse.equinox.http.servlet.internal.servlet.ProxyServlet.service(ProxyServlet.java:74)
Caused by: org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: org/jsoup/Jsoup
	at org.glassfish.jersey.servlet.internal.ResponseWriter.rethrow(ResponseWriter.java:278)
	at org.glassfish.jersey.servlet.internal.ResponseWriter.failure(ResponseWriter.java:260)
	at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:509)
	at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:334)
	at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
	at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
	at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
	at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305)
Caused by: java.lang.NoClassDefFoundError: org/jsoup/Jsoup
	at org.openhab.binding.kevoplus.internal.discovery.KevoLockDiscovery$login.status(KevoLockDiscovery.java:40)
	at org.openhab.binding.kevoplus.internal.discovery.KevoLockDiscovery.startScan(KevoLockDiscovery.java:77)
	at org.eclipse.smarthome.config.discovery.AbstractDiscoveryService.startScan(AbstractDiscoveryService.java:222)
	at org.eclipse.smarthome.config.discovery.internal.DiscoveryServiceRegistryImpl.startScan(DiscoveryServiceRegistryImpl.java:409)
	at org.eclipse.smarthome.config.discovery.internal.DiscoveryServiceRegistryImpl.startScans(DiscoveryServiceRegistryImpl.java:394)
	at org.eclipse.smarthome.config.discovery.internal.DiscoveryServiceRegistryImpl.startScan(DiscoveryServiceRegistryImpl.java:241)
	at org.eclipse.smarthome.io.rest.core.internal.discovery.DiscoveryResource.scan(DiscoveryResource.java:97)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)

After tearing my hair out going around in circles through google searches I have decided it is time to throw it out to the brains trust and hope someone can help me out with where I am going wrong.

Seeing as I accidentally seem to have managed to get this thread to the top of some google searches I thought i’d better list what I can remember that I have tried which hasn’t worked for me but has apparently worked for others with similar problems.

Worked for me:
In META-INF/manifest.mf , make sure Bundle-ClassPath includes the jar not just the folder eg.

Bundle-ClassPath: ., libs/jsoup-1.11.2.jar

Didn’t work for me (but may have been needed as it was tried on my path to a solution:

  • Place the .jar in a lib/libs folder at the root of the project
  • Right click on the .jar Build Path > Add to build path (configure build path, Libraries, Add JARs)
  • Build Configuration, Order and Export, tick next to the .jar
  • Refresh after every change, Clean after every change, close/open Eclipse after every change
  • In the pom.xml try adding the dependency (if using maven) eg.

<dependencies> <dependency> <groupId>org.jsoup</groupId> <artifactId>jsoup</artifactId> <version>1.11.2</version> </dependency> </dependencies>

Hope that can help someone out.