简体   繁体   中英

JSOUP Unresolved compilation: ignoreHttpErrors() is undefined for the type Connection

I'm getting this error when calling ignoreHttpErrors(boolean) using JSoup 1.6.3

Exception in thread "main" java.lang.Error: Unresolved compilation problem: The method ignoreHttpErrors(boolean) is undefined for the type Connection

Is it a referencing problem with my setup? Any idea how to fix it?

Eclipse validates the code with no errors and 1 warning.

The following code won't compile.

try {

            Connection.Response response =   Jsoup.connect(url)
                    .userAgent("Mozilla/5.0 (Windows NT 6.0) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.46 Safari/536.5")
                    .timeout(10000)
                    .followRedirects(false)
                    .ignoreHttpErrors(true)  // <--- Underlined red in eclipse plus the error msg
                    .execute();

            int statusCode = response.statusCode();
            System.out.println("received status code : " + statusCode);
            if(statusCode == 200) {
                System.out.println("Found : " + statusCode);                    
            }
            else if(statusCode == 404){
                System.out.println("Not Found : " + statusCode);                    
            }
            else if(statusCode == 302){
                System.out.println("Page Moved : " + statusCode);                   
            }

        } catch (SocketTimeoutException e) {
            System.out.println("Timeout occured");

        } catch (IOException e) {
            System.out.println("I/O problem");
        } 

EDIT 1

import org.jsoup.Connection;
import org.jsoup.nodes.Document;

System.out.println(Connection.class.getProtectionDomain().getCodeSource().getLocation());
System.out.println(Document.class.getProtectionDomain().getCodeSource().getLocation());

Output

file:/C:/opt/glassfish/glassfish/modules/bean-validator.jar
file:/C:/opt/glassfish/glassfish/modules/bean-validator.jar

Hmmm, not what I was expecting at all. I have jsoup-1.6.3.jar in the Library Directory of my EAR. The calling code is in an EJB packaged within the EAR.

Thoughts?

The ignoreHttpErrors() method is new since 1.6.0 . Apparently you've still an older version of Jsoup somewhere in the classpath which got precedence in classloading.

To nail down its exact location in the classpath, execute the following

System.out.println(Connection.class.getProtectionDomain().getCodeSource().getLocation());

Where Connection is obviously the Jsoup one. It should then be a matter of removing the duplicate older versioned JAR file at the given location.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM