【问题标题】:HttpUnit imports not found in Eclipse在 Eclipse 中找不到 HttpUnit 导入
【发布时间】:2018-10-30 21:27:31
【问题描述】:

我正在尝试开始使用 HttpUnit。我用一个简单的例子制作了一个 Eclipse 项目,但似乎有一个永无止境的未解决依赖项和它找不到的导入流。所以我要重新开始:

我只想让本教程正常工作:http://www.httpunit.org/doc/tutorial/

我的 jars 文件夹包含:

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

我的 .classpath 文件说:

<?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>

为什么以下导入无法解析?

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

谢谢

【问题讨论】:

    标签: eclipse import dependencies http-unit


    【解决方案1】:

    Package ExplorerProject Explorer 视图中选择所有 JAR右键单击并选择 构建路径 > 添加到构建路径

    如果你这样做了,.classpath 文件应该为每个.jar 文件都有一个类似&lt;classpathentry kind="lib" path="... .jar"/&gt; 的条目。

    【讨论】:

    • 我做了,但没用。作为教程一部分的常规文件 BettingPool.java 和 BettingPoolGame.java 工作正常,因为它们没有导入。但我提到的导入示例文件仍然没有。
    • 您还需要正确的 JAR,例如。 G。对于前两个导入 httpunit.jar.
    • 谢谢,成功了!终于可以编译了真是太好了。不幸的是,现在当我尝试获取 webresponse 时出现运行时错误:未找到 Rhino 类 (js.jar) - Javascript disabled 线程“main”java.lang.NoClassDefFoundError 中的异常:org/mozilla/javascript/Scriptable(我应该做一个新线程?毕竟它仍然涉及让 Httpunit 工作)
    • Java 构建路径 上缺少 js JAR,或者 JAR 的版本错误。使用 Maven 或 Gradle 会更容易:所有正确的 JAR 都会自动下载并添加到 Java 构建路径mvnrepository.com/artifact/org.httpunit/httpunit/1.7.2
    【解决方案2】:

    作为 httpunit 提交者之一,我建议使用 maven 依赖项。

    M2Eclipse 插件将帮助您使用 maven:

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

    截至 2018 年 9 月,您可以为 httpunit 使用 1.7.3 版依赖项。然后自动解决所有其他依赖项。

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

    https://mvnrepository.com/artifact/org.httpunit/httpunit,您将找到最新版本。

    如果你想找出 httpunit 自己的依赖,你可以运行:

    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] ------------------------------------------------------------------------
    

    【讨论】:

      猜你喜欢
      • 2011-03-09
      • 1970-01-01
      • 1970-01-01
      • 2020-07-25
      • 1970-01-01
      • 2015-03-19
      • 1970-01-01
      • 2015-12-30
      • 1970-01-01
      相关资源
      最近更新 更多