0

I have a weird issue with eclipse,
I get ClassNotFoundException when trying to run a very basic example of jsoup 1.10.3
This is the code that I an trying out:

String html = "<p>An <a href='http://example.com/'><b>example</b></a> link.</p>";
Document doc = Jsoup.parse(html); // exception here

this is the exception:

Caused by: java.lang.ClassNotFoundException: org.jsoup.Jsoup
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

As far as eclipse - I added the JSoup jar (right click add to build path)
I have no compilation issues, I can actually see the autocomplete for the jsoup members and functions.
in the eclipse .classpath file i can see that the JSoup jar is there,
here is the file content:

<classpath>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="lib" path="lib/javax.mail-1.6.0.jar"/>
    <classpathentry kind="lib" path="lib/jsoup-1.10.3.jar"/>
    <classpathentry kind="output" path="bin"/>

What I tried until now:
eclipse->clean
eclipse->delete project and recreate
eclipse->restart eclipse
eclipse Project ->lower the compiler version from 1.8 to 1.7, 1.6,1.5
researched dependencies, according to the Jsoup site: Dependencies jsoup is entirely self contained and has no dependencies.
I found many similar posts in stackoverflow all pointing to class path issue, but this case is different.

search git for similar issues: https://github.com/jhy/jsoup/issues?utf8=%E2%9C%93&q=ClassNotFoundException nothing helps

Is it possible that there is a static initialization in the Jsoup class for other class missing that is causing this odd issue?

image from eclipse

JavaSheriff
  • 7,074
  • 20
  • 89
  • 159
  • 1
    Did you also add it to your runtime path? – scrappedcola Aug 22 '17 at 21:07
  • hi, not sure about the runtime path can you elaborate more? see the new image I added to the question – JavaSheriff Aug 22 '17 at 21:14
  • 1
    Search "eclipse Runtime path" in the search bar above or on google ( or checkout the Run/Debug Settings in your added preferences image). Build time and run time are 2 very separate concepts. Specifying you jsoup in the build path only ensures that javac knows about it. The runtime is a different component that needs to know where it exists as well. – scrappedcola Aug 22 '17 at 21:16
  • 2
    Depending on how you're running your application, the Java Build Path *is* the runtime path. What are you doing to run your application? – nitind Aug 22 '17 at 21:42
  • run as java application, nothing fancy – JavaSheriff Aug 23 '17 at 01:09
  • 2
    https://stackoverflow.com/questions/10383226/how-do-i-set-the-runtime-classpath-in-eclipse-4-2 walks you through adding libs to your runtime classpath. Also possible duplicate of https://stackoverflow.com/questions/764614/my-code-compiles-in-eclipse-but-i-get-a-classnotfound-at-runtime-how-can-i-fix-i. Generally if your brought in libs aren't apart of you path (ie you have to add them to your build classpath) you also have to add them to your runtime class path. – scrappedcola Aug 23 '17 at 14:03

1 Answers1

0

enter image description here

After a long investigation I found out that the organization introduced new pc protection called Bromium
it will block JARS until told otherwise
So I had to mark the jar as trusted
This solved the issue.

JavaSheriff
  • 7,074
  • 20
  • 89
  • 159