使用 Jsoup 构建基本程序
在构建/运行 Java 框架以利用 Jsoup 时遇到一个非常基本的问题:
import org.jsoup.Jsoup;
public class ProtoType {
public static void main(String[] args) throws Exception {
Jsoup.parse("");
}
}
$ ls
jsoup-1.4.1.jar ProtoType.java
$ echo $CLASSPATH
.:/usr/lib/jvm/java-6-openjdk/jre/lib:~/tmp/test
$ javac -classpath ./jsoup-1.4.1.jar ProtoType.java
$ java ProtoType
Exception in thread "main" java.lang.NoClassDefFoundError: org/jsoup/Jsoup
at ProtoType.main(ProtoType.java:6)
Caused by: java.lang.ClassNotFoundException: org.jsoup.Jsoup
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
... 1 more
$
我缺少什么?
Having a very basic problem here building/running a Java skeleton to make use of Jsoup:
import org.jsoup.Jsoup;
public class ProtoType {
public static void main(String[] args) throws Exception {
Jsoup.parse("");
}
}
$ ls
jsoup-1.4.1.jar ProtoType.java
$ echo $CLASSPATH
.:/usr/lib/jvm/java-6-openjdk/jre/lib:~/tmp/test
$ javac -classpath ./jsoup-1.4.1.jar ProtoType.java
$ java ProtoType
Exception in thread "main" java.lang.NoClassDefFoundError: org/jsoup/Jsoup
at ProtoType.main(ProtoType.java:6)
Caused by: java.lang.ClassNotFoundException: org.jsoup.Jsoup
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
... 1 more
$
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是您已经告诉
javac
在哪里可以找到 jsoup,但没有告诉java
。解决方案是将
-classpath ./jsoup-1.4.1.jar
添加到对java
的调用中。所以
The problem is that you've told
javac
where to find jsoup, but you haven't toldjava
.The solution is to add
-classpath ./jsoup-1.4.1.jar
to your call tojava
.So
这是一个简单的 javaSE 程序,它使用 jsoup 1.8 库来解析网站并从中获取内容。
希望这对尝试使用该库的每个人都有帮助:)
this is a simple javaSE program that use jsoup 1.8 library to parse a website and get content from it .
hope this will be helpful for everyone who tries to use that library :)