1

I'm trying to create executable jar for Maven Selenium/TestNG/Java test automation project, but I keep getting "Error: Could not find or load main class" when running .jar file.
To make sure it is indeed Browsermob causing jar to fail, I created a new maven project, which has a single file in src\main\java directory

public class Test2 {
    public static void main(String[] args) {
        System.out.println("works");    
    }
}

I'm using IntelliJ and when create .jar (Project Structure > Artifacts > JAR > From modules... etc) without Browsermob dependency everything is fine. But as soon as I add Browsermob to it .jar starts to fail with "Error: Could not find or load main class".

Error: Could not find or load main class Test2
Caused by: java.lang.ClassNotFoundException: Test2

Other dependencies don't seem to cause any trouble.

pom.xml just in case:

<?xml version="1.0" encoding="UTF-8"?>
<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>JarTest</groupId>
    <artifactId>gpn</artifactId>
    <version>1.0-SNAPSHOT</version>

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

What could be the reason?

cloudhunt
  • 13
  • 3

1 Answers1

0

For packaging a runnable plugin in Maven you need a dedicated plugin. There are many you can choose between, look here for more info, or also here

Leviand
  • 2,567
  • 3
  • 24
  • 35
  • 1
    Thank you! The 1st link actually helped. – cloudhunt Jul 20 '18 at 12:15
  • Although now I added `TestNG testng = new TestNG();` in main method (also testng dependency to pom) and it fails with `Exception in thread "main" java.lang.NoClassDefFoundError: org/testng/TestNG at Test2.main`, but I guess it's a different problem – cloudhunt Jul 20 '18 at 12:20
  • Yes it's differet; if the answer was helpful please upvote and flag as valid answer :) – Leviand Jul 20 '18 at 12:37
  • I tried to upvote, but I'm new here and don't have enough reputation for my upvote to count apparently( sorry about that! – cloudhunt Jul 20 '18 at 12:41