문제

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?

도움이 되었습니까?

해결책

The problem is that you've told javac where to find jsoup, but you haven't told java.

The solution is to add -classpath ./jsoup-1.4.1.jar to your call to java.

So

java -classpath ./jsoup-1.4.1.jar:. ProtoType

다른 팁

import java.io.IOException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;


public class SecondTryBourse {
    public static void main(String[] args) throws IOException {
        Document doc = Jsoup.connect("http://www.bvmt.com.tn/").get();
        Elements els = doc.select("#center  #block-bvmt-blocks-hp-block-lastnews  > div");

        Elements el = els.select("div.block-content").select("ul.actu li.avis p.dateavis");
        System.out.println("this is out elements"+ els);
        System.out.println("\n tuutut \n"+ el.text());

}
}

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 :)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top