File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Testing and the fly likes Help using htmlunit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Help using htmlunit" Watch "Help using htmlunit" New topic
Author

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.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
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 java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
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.loadWebResponseInto(WebClient.java:431)
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: 24187
    
  34

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


[Jess in Action][AskingGoodQuestions]
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?

Instead of having your classpath say "file1;file2;file3", make it say "c:\path\to\file1;c:\path\to\file2;c:\path\to\file3".
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help using htmlunit