Phonzi Phonzi - 3 years ago 190
Java Question

Exceptions in downloading htmlunit

I am in the process of downloading and using htmlunit for Java. I installed the 2.27 version (I believe this is the latest version) as a jar file and expanded it. The code is riddled with lines that cause compiler exceptions such as the following.

//Code from the WebClient class
//The switch statement has the error according to the compiler.
public WebResponse loadWebResponse(WebRequest webRequest)
throws IOException
{
String str;

switch ((str = webRequest.getUrl().getProtocol()).hashCode()) {case 3076010: if (str.equals("data")) {} break; case 3143036: if (str.equals("file")) break; case 92611469: if ((goto 107) && (str.equals("about")))
{
return makeWebResponseForAboutUrl(webRequest.getUrl());


return makeWebResponseForFileUrl(webRequest);


return makeWebResponseForDataUrl(webRequest);
}
break; }
return loadWebResponseFromWebConnection(webRequest, 20);
}


Has anyone else had this problem? If so, how did you deal with it?

(Ps. I'm sorry for the real long line; I wanted to keep it formatted the same was as in the original code)

Answer Source

Try to follow these steps:

  1. Go to http://htmlunit.sourceforge.net/
    Under Where to find... click the link below Latest release
  2. Click on the file link that ends with .bin.zip
    After downloading, extract all files to a folder, keeping the folder hierarchy.
  3. Add all the JAR files found at the /lib sub-folder to your Java project's CLASSPATH.
  4. Import classes, like this:
    import com.gargoylesoftware.htmlunit.WebCli‌​ent;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download