Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
210 views
in Technique[技术] by (71.8m points)

java - Updating to htmlunit 2.37.0: setTimeout() build failure

Hej.

First of all: sorry for maybe asking a very simple question, I am very new to Java.

Here is my problem: I updated the dependenciy of an ancient code from using net.sourceforge.htmlunit version 2.8 to 2.37.0 (this was recommended by the Github security bot).

Now my code is not compiling and throws two errors.

Here is the relevant code:

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;

...

WebClient webClient = new WebClient(FIREFOX_3);
webClient.setTimeout(50000);
HtmlPage page = webClient.getPage("http://king.smith.man.ac.uk/mcpred/");
  1. First error:
[ERROR] ./MissedCleavageAnalysisAdaptor.java:[64,53] cannot find symbol
[ERROR]   symbol:   variable FIREFOX_3
  1. Second error:
[ERROR] ./MissedCleavageAnalysisAdaptor.java:[65,26] cannot find symbol
[ERROR]   symbol:   method setTimeout(int)

I managed to avoid the first error by simply deleting the "FIREFOX_3". Using "FIREFOX" (= newest version of firefox) or "FIREFOX_78" instead did not work and threw the same error.

With the second error, I cannot see the problem. I tried other integers or first defining an integer int timeout = 50000; and webClient.setTimeout(timeout);. Always the same error occurs. It seems like the method setTimeout was not imported. However, this should be imported together with WebClient, shouldn't it?

Can you please give me a hint how to tackle these errors?

Thanks a lot!

question from:https://stackoverflow.com/questions/65884322/updating-to-htmlunit-2-37-0-settimeout-build-failure

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Wow thats a huge jump 2.8 was released Aug 5, 2010 and 2.37 in January 28, 2020. The current version is 2.46.0 rom January 2, 2021 - maybe it makes sense to directly migrate to this one.

If you have a look at the release notes you will find this line:

WebClient: deprecated setTimeout() and getTimeout(). Use webClient.getOptions() instead.

for the release 2.11. Means - you have to change your code like this:

webClient.getOptions().setTimeout(50000);

The whole release notes are available here https://htmlunit.sourceforge.io/changes-report.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...