I was attempting to use httpunit 1.7 under Java 1.5/5.0 for testing a servlet. Since no JavaScript is involved, I shouldn't need to include "js.jar" or otherwise include the Mozilla Rhino JavaScript engine. As implied on the httpunit FAQ, if this library is missing, JavaScript features should be disabled, without breaking httpunit.
However, I'm experiencing a NoClassDefFoundError for org/mozilla/javascript/Scriptable. The relevant stack trace is attached. It seems to point to something within the static initialization of com.meterware.httpunit.ParsedHTML.<clinit>(ParsedHTML.java:724) eventually attempting to load "org.mozilla.javascript.Scriptable".
The error can simply be reproduced by initializing ParsedHTML by calling the only publicly accessible static method: ParsedHTML.isWebLink(null).
Also somewhat related: During initializing, the following is output to stderr: "Rhino classes (js.jar) not found - Javascript disabled". An option should be made available to expect this configuration and disable the warning. Alternatively, utilize a logging framework e.g. SLF4J or JDK1.4's logging to log this warning instead of writing to stderr.
If you have a fix for this, I would be very happy to incorporate
it. Please include a test case or instructions for duplicating
the problem.
Dear Mark,
thank you for pointing this out. Unfortunately our developer resources are limited. If you have a fix and some testCase (in your case it would probably be some kind of commandline call of httpunit with setting the classpath) I'll happily commit the result.
Thanks for your support.
Yours
Wolfgang
For me, this different ClassNotFounds, for
java.lang.LinkageError: Failed to link com/meterware/httpunit/dom/AbstractDomComponent
and also for HTMLControl.
This is very bad.
Also, nowadys it's hard to come up with a matching JTidy version...
The latest version of httpunit now uses Maven to manage its dependencies. I would advise upgrading to deal with the parser issue (although I'd recommend using NekoHtml, which should be the default).
The linkage error is the result of reworking the classes several years ago to simplify the Javascript implementation. It is no longer possible to work without Rhino, as the various object classes now extend Rhino classes. The documentation would need to be fixed.
Thanks Russell.
Actually, I am looking at httpunit at mavenhub.com now.
Still, this will add some really old dependencies to any project...
For the record (even if offtopic here), it works by just using
http://repo1.maven.org/maven2/httpunit/httpunit/1.7/httpunit-1.7.jar
http://repo1.maven.org/maven2/xerces/xmlParserAPIs/2.2.1/xmlParserAPIs-2.2.1.jar
http://repo1.maven.org/maven2/xerces/xercesImpl/2.6.2/xercesImpl-2.6.2.jar
http://repo1.maven.org/maven2/nekohtml/nekohtml/0.9.5/nekohtml-0.9.5.jar
http://repo1.maven.org/maven2/rhino/js/1.6R5/js-1.6R5.jar
Javascript-Support should be optional though, since Rhino is not capable of working with JQuery (and thus most modern pages) anyway.
Still, HttpUnit is the best choice for certain use cases even in 2014.
If somebody plans to give it some new life, like updating dependencies and such, contact me to see if I can help...
Ah, now that is useful information. When I started down this path several years ago, I had expected to have time to address incompatibilities and ultimately keep up with Rhino releases or whatever will replace it. Not sure how much time I have to give to this, but if you have ideas on how to move forward, I'd be happy to work with you.