1

I'm trying to get started with HttpUnit. I made an Eclipse project with a simple example, but there seems to be a neverending stream of unresolved dependencies and imports it can't find. So I'm starting over:

I just want to get this tutorial to work: http://www.httpunit.org/doc/tutorial/

My jars folder contains:

activation-1.1.jar
js-1.6R5.jar
jtidy-4aug2000r7-dev.jar
junit-3.8.1.jar
mail-1.4.jar
nekohtml-0.9.5.jar
servlet-api-2.4.jar
xercesImpl-2.6.1.jar
xmlParserAPIs-2.6.1.jar

My .classpath file says:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="src" path="jars"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

Why can't the following imports be resolved?

import com.meterware.httpunit.*;
import com.meterware.servletunit.*;
import junit.framework.*;

Thanks

MJL
  • 352
  • 3
  • 11

2 Answers2

0

In the Package Explorer or Project Explorer view select all JARs, right-click and choose Build Path > Add to Build Path.

If you did that, the .classpath file should have an entry like <classpathentry kind="lib" path="... .jar"/> for each .jar file.

howlger
  • 31,050
  • 11
  • 59
  • 99
  • I did, but that didn't work. The regular files BettingPool.java and BettingPoolGame.java which are part of the tutorial work fine cause they have no imports. But my example file with the mentioned import still doesn't. – MJL May 22 '18 at 17:54
  • You also need the correct JARs, e. g. for the first two imports [`httpunit.jar`](http://www.java2s.com/Code/Jar/h/Downloadhttpunitjar.htm). – howlger May 22 '18 at 18:14
  • Thanks, that worked! It's great to finally have it compile. Unfortunately now there's a runtime error when I try to get a webresponse: Rhino classes (js.jar) not found - Javascript disabled Exception in thread "main" java.lang.NoClassDefFoundError: org/mozilla/javascript/Scriptable (Should I make a new thread for that? It still concerns getting Httpunit to work, after all) – MJL May 27 '18 at 14:31
  • 1
    Either the js JAR is missing on the _Java Build Path_ or a JAR has the wrong version. With Maven or Gradle it would be easier: all correct JARs would be automatically downloaded and added to the _Java Build Path_: https://mvnrepository.com/artifact/org.httpunit/httpunit/1.7.2 – howlger May 27 '18 at 15:19
0

As one of the httpunit committers I'd recommend to use the maven dependency.

The M2Eclipse plugin will help you to use maven:

https://www.eclipse.org/m2e/

as of 2018-09 you can use the version 1.7.3 dependency for httpunit. Then all other depencencies are automatically resolved.

<!-- https://mvnrepository.com/artifact/org.httpunit/httpunit -->
<dependency>
    <groupId>org.httpunit</groupId>
    <artifactId>httpunit</artifactId>
    <version>1.7.3</version>
    <scope>test</scope>
</dependency>

at https://mvnrepository.com/artifact/org.httpunit/httpunit you'lll aways find the latest release.

If you'd like to find out httpunit's own dependencies you can run:

mvn dependency:tree
[INFO] Scanning for projects...
[INFO] 
[INFO] -----------------------< org.httpunit:httpunit >------------------------
[INFO] Building HttpUnit 1.7.4-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ httpunit ---
[INFO] org.httpunit:httpunit:jar:1.7.4-SNAPSHOT
[INFO] +- rhino:js:jar:1.6R5:compile
[INFO] +- junit:junit:jar:4.10:compile
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.1:compile
[INFO] +- nekohtml:nekohtml:jar:0.9.5:compile
[INFO] +- javax.servlet:servlet-api:jar:2.4:compile
[INFO] +- net.sf.jtidy:jtidy:jar:r938:compile
[INFO] +- xerces:xercesImpl:jar:2.6.1:compile
[INFO] +- xerces:xmlParserAPIs:jar:2.6.1:compile
[INFO] \- javax.mail:mail:jar:1.4:test
[INFO]    \- javax.activation:activation:jar:1.1:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.670 s
[INFO] Finished at: 2019-06-15T15:07:46+02:00
[INFO] ------------------------------------------------------------------------
Wolfgang Fahl
  • 15,016
  • 11
  • 93
  • 186