2

Hey guys my first post here.. I'm trying to setup Selenium and Browsermob Proxy in Java in Embedded Mode (gotta to say that I never used Maven, Selenium or BrowserMob Proxy before). Following the Github instructions of BrowserMob Proxy I set up a Maven-Project in Eclipse and added both dependencies in 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>

In order to test whether it works...

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);
}}

... I get this errordialog followed by this exception..

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

When I remove the last to lines from the main method it works without problems. Does anyone has an idea what I'm doing wrong here? Thanks in advance.

P.Raber
  • 68
  • 5

1 Answers1

2

Can you replace

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

with

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

and give it a try? Could be an issue with dependency resolution of POM file.

Bharadwaj Pendyala
  • 317
  • 1
  • 3
  • 16
  • 1
    Pretty sure I tried this before and it didn't work. But I tried again now and it solved the problem... ;) Thanks a lot. – P.Raber Oct 26 '18 at 11:19