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