Big Moose Saloon
 Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies Register / Login Win a copy of Refactoring for Software Design Smells: Managing Technical Debt this week in the OO, Patterns, UML and Refactoring forum!

# Help using htmlunit

Kris Bauer
Greenhorn

Joined: Aug 02, 2006
Posts: 4
I keep getting this error when trying to run just a simple test program.

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xerces/parsers/AbstractSAXParser
at java.net.URLClassLoader.access$100(URLClassLoader.java:56) at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:214)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:112)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:85)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:335)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:389)

I can't seem to find help on this subject anywhere.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Sounds as if you have no, or a wrong version of, Jakarta Xerces in the classpath.

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Kris Bauer
Greenhorn

Joined: Aug 02, 2006
Posts: 4
java -cp .:commons-beanutils-1.7.0.jar:commons-cli-1.0.jar:commons-codec-1.3.jar:commonc-collections-3.2.jar:commons-httpclient-3.0.1.jar:commons-io-1.2.jar:commons-jelly-1.0.jar:commons-jelly-tags-log-1.0.jar:commons-jexl-1.0.jar:commons-lang-2.1.jar:commons-logging-1.1.jar :dom4j-1.6.1.jar:htmlunit-1.9.jar:jaxen-1.1-beta-9.jar:js-1.6R2.jar:nekohtml-0.9.5.jar:xerceslmpl-2.6.2.jar:xmlParserAPIs-2.6.2.jar

That's my classpath. I'm running this on a Mac, if that makes any difference.
[ August 03, 2006: Message edited by: Kris Bauer ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24189

34

I'm going to move this to our "Testing" forum.

Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962

5
Can you see the class "org/apache/xerces/parsers/AbstractSAXParser.class" inside "xerceslmpl-2.6.2.jar"? If not, then you probably should use whatever version of Xerces HtmlUnit comes with.

Oh, and when your classpath looks like this:
Originally posted by Kris Bauer:
java -cp .:commons-beanutils-1.7.0.jar:commons-cli-1.0.jar:commons-codec-1.3.jar:commonc-collections-3.2.jar:commons-httpclient-3.0.1.jar:commons-io-1.2.jar:commons-jelly-1.0.jar:commons-jelly-tags-log-1.0.jar:commons-jexl-1.0.jar:commons-lang-2.1.jar:commons-logging-1.1.jar om4j-1.6.1.jar:htmlunit-1.9.jar:jaxen-1.1-beta-9.jar:js-1.6R2.jar:nekohtml-0.9.5.jar:xerceslmpl-2.6.2.jar:xmlParserAPIs-2.6.2.jar

all those .jar files should reside in the current working directory where you're invoking the JVM. Is that true in your case?

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Kris Bauer
Greenhorn

Joined: Aug 02, 2006
Posts: 4
How would I check to see if the xerces jar contains that file?
It is the version that came with htmlunit.

And all of those jars are where the java file is.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Kris Bauer:
How would I check to see if the xerces jar contains that file?

jar files are basically zip files ,so you can use any zip utility you want.

It is the version that came with htmlunit.

Then it should probably be ok.

And all of those jars are where the java file is.

Using your command line, they need to be in the folder you are starting the command from. You would be save if you used absolute paths.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962

5
Originally posted by Kris Bauer:
How would I check to see if the xerces jar contains that file?

As Ilja already mentioned, JAR files are just ZIP files that contain some special files for the JVM to interpret so you can use any archive management software that supports ZIP. If you're using Windows, WinZip or WinRAR would be examples of such software.

Having said that, you can also use the command line for figuring out a JAR file's content:
Kris Bauer
Greenhorn

Joined: Aug 02, 2006
Posts: 4
I checked the jar file and it contains the AbstractSAXParser.class file.
How would I go about doing the absolute paths?
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962

5
Originally posted by Kris Bauer:
How would I go about doing the absolute paths?