运行时的Jsoup错误:线程“主”中的异常java.lang.NoClassDefFoundError [英] Jsoup error at run time: Exception in thread "main" java.lang.NoClassDefFoundError

查看:596
本文介绍了运行时的Jsoup错误:线程“主”中的异常java.lang.NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下错误

Exception in thread "main" java.lang.NoClassDefFoundError: org/jsoup/Jsoup
    at Main.main(Main.java:42)
Caused by: java.lang.ClassNotFoundException: org.jsoup.Jsoup
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    ... 1 more

现在我已经做了以下工作:

Now what I have done so far:

我在我的项目文件夹中创建了一个libs文件夹,并添加了 Jsoup.jar 那里。然后在eclipse中单击属性,添加外部Jar并添加它。我看到引用的库。

I created a libs folder in my project folder and added the Jsoup.jar there. Then in eclipse I click properties, add external Jar and added it. I see the referenced library.

但问题依然存在。我没有得到编译错误。所以这是一个运行时问题。欣赏帮助。

But the issue still persist. I dont get compilation errors. So this is a runtime issue. Appreciate the help.

编辑:
我找到了以下
如果我使用

I have found the following If I compile using

  javac -classpath /path/to/jsoup.jar myclass.java

然后

  java -classpath /path/to/jsoup.jar myclass

它运行完美。
现在这对我来说不起作用,因为我将在没有Jsoup的计算机上使用我的应用程序。那么如何解决这个运行时问题?

It runs perfect. Now. This is not working for me because I am going to use my application on a computer that does not have Jsoup. So how to I resolve this runtime issue?

推荐答案

转到运行配置... 菜单,并检查运行任务的类路径。您似乎添加了编译步骤的库,但在运行步骤中没有设置。

Go to Run configurations... menu and check classpath for Run task. It looks like you add library for Compilation step, but it doesn't set at Run step.

编辑(注释后)

我遇到这个问题,发现应用程序容器需​​要这种依赖关系。所以你只需要添加这个库到你的应用程序服务器的classpath。如果您使用Tomcat,只需将库放到%CATALINA_HOME%\lib 目录。

I dove into the issue and found that this dependency is needed for application container. So you just need to add this library to classpath of your app server. If you use Tomcat, just put the library to the %CATALINA_HOME%\lib directory.

这篇关于运行时的Jsoup错误:线程“主”中的异常java.lang.NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆