尝试以嵌入式模式启动 BrowserMobProxyServer 时发生 JNI 错误(Java,Maven)

JNI-error occuring when trying to start BrowserMobProxyServer in Embedded Mode (Java, Maven)

大家好,这是我的第一个 post。我正在尝试在 Java 的嵌入式模式中设置 Selenium 和 Browsermob 代理(不得不说我从未使用过 Maven、Selenium 或 BrowserMob 代理前)。按照 BrowserMob Proxy 的 Github 说明,我在 Eclipse 中设置了一个 Maven 项目,并在 pom.xml.

中添加了两个依赖项
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ba</groupId>
<artifactId>com.ba.project</artifactId>
<version>0.0.1-SNAPSHOT</version>

<dependencies>
    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.14.0</version>
    </dependency>

<dependency>
    <groupId>net.lightbody.bmp</groupId>
    <artifactId>browsermob-core</artifactId>
    <version>2.1.5</version>
    <scope>test</scope>
</dependency>
</dependencies>

为了测试是否有效...

public class Test {
public static void main(String[] args) {
    System.setProperty("webdriver.gecko.driver", "...");
    WebDriver driver = new FirefoxDriver();
    BrowserMobProxy proxy = new BrowserMobProxyServer();
    proxy.start(0);
}}

...我得到 this errordialog 其次是这个异常..

Exception in thread "main" java.lang.NoClassDefFoundError: net/lightbody/bmp/BrowserMobProxy
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: 
net.lightbody.bmp.BrowserMobProxy
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more

当我从 main 方法中删除最后一行时,它可以正常工作。 有谁知道我在这里做错了什么?提前致谢。

你能代替

<dependency>
    <groupId>net.lightbody.bmp</groupId>
    <artifactId>browsermob-core</artifactId>
    <version>2.1.5</version>
    <scope>test</scope>
</dependency>

<dependency>
    <groupId>net.lightbody.bmp</groupId>
    <artifactId>browsermob-core</artifactId>
    <version>2.1.5</version>
</dependency>

并试一试?可能是 POM 文件的依赖解析问题。