0

最近我一直在尝试使用 HtmlUnit API,但由于某种原因,我无法拥有我需要的所有依赖项。我做的第一件事是访问 HtmlUnit 站点并搜索依赖项的完整列表 ( http://htmlunit.sourceforge.net/dependencies.html )。然后我搜索了它们中的每一个的 maven 依赖项,直到我创建了最终的 pom.xml:

<?xml version="1.0" encoding="UTF-8"?>

http://maven.apache.org/xsd/maven-4.0.0.xsd">4.0.0

<groupId>it.auties</groupId>
<artifactId>it.auties</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>8</source>
                <target>8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>spigot-repo</id>
        <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
    </repository>
    <repository>
        <id>vault-repo</id>
        <url>http://nexus.hc.to/content/repositories/pub_releases</url>
    </repository>
    <repository>
        <id>wesjd-repo</id>
        <url>https://nexus.wesjd.net/repository/thirdparty/</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>org.spigotmc</groupId>
        <artifactId>spigot-api</artifactId>
        <version>1.13.2-R0.1-SNAPSHOT</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>net.milkbowl.vault</groupId>
        <artifactId>VaultAPI</artifactId>
        <version>1.7</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>net.wesjd</groupId>
        <artifactId>anvilgui</artifactId>
        <version>1.2.1-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>net.sourceforge.htmlunit</groupId>
        <artifactId>htmlunit</artifactId>
        <version>2.33</version>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.6</version>
    </dependency>
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>commons-net</groupId>
        <artifactId>commons-net</artifactId>
        <version>3.6</version>
    </dependency>
    <dependency>
        <groupId>net.sourceforge.htmlunit</groupId>
        <artifactId>htmlunit-core-js</artifactId>
        <version>2.33</version>
    </dependency>
    <dependency>
        <groupId>net.sourceforge.htmlunit</groupId>
        <artifactId>htmlunit-cssparser</artifactId>
        <version>1.2.0</version>
    </dependency>
    <dependency>
        <groupId>net.sourceforge.htmlunit</groupId>
        <artifactId>neko-htmlunit</artifactId>
        <version>2.33</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.8</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-text</artifactId>
        <version>1.4</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpmime</artifactId>
        <version>4.5.6</version>
    </dependency>
    <dependency>
        <groupId>org.eclipse.jetty.websocket</groupId>
        <artifactId>websocket-client</artifactId>
        <version>9.4.12.v20180830</version>
    </dependency>
    <dependency>
        <groupId>xalan</groupId>
        <artifactId>xalan</artifactId>
        <version>2.7.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.5.6</version>
    </dependency>
</dependencies>

我启动了我的服务器,但是当插件加载时(我正在开发一个 spigotMC.org 插件),我得到一个 NoClassDefFoundException: java.lang.NoClassDefFoundError: com/gargoylesoftware/htmlunit/WebClient

4

1 回答 1

0

您是否尝试过仅用这个替换所有这些依赖项:

<dependency>
  <groupId>net.sourceforge.htmlunit</groupId>
  <artifactId>htmlunit</artifactId>
  <version>2.4</version> <!-- use version that is suitable for you -->
</dependency>

如果您需要使用 HtmlUnit,只需将其作为依赖项添加到您的项目中,Mavne 将自行下载所有传递依赖项。这是来自 HtmlUnit 的 Maven 回购链接: https ://mvnrepository.com/artifact/net.sourceforge.htmlunit/htmlunit/2.4

于 2019-01-03T19:48:46.170 回答