0

I have a program that connects Selenium. The program opens the page in the browser, logs in, regularly updates the page and sends me an email if there is a change. My system Linux Mint 21.1. I use maven. If I run it in IntelliJ IDEA it works. I collect the jar file, run it in terminal and get the error:

user@user-HYM-WXX:~/Desktop/sender$ java -jar sendmailer.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
    at org.example.App.main(App.java:16)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.WebDriver
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    ... 1 more

My pow.xml:

<?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>org.example</groupId>
    <artifactId>sendmailer</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>3.2.0</version>
                    <configuration>
                        <archive>
                            <manifest>
                                <mainClass>org.example.App</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
    <dependencies>

        <dependency>
            <groupId>com.sun.mail</groupId>
            <artifactId>javax.mail</artifactId>
            <version>1.6.2</version>
        </dependency>


        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.8.1</version>
        </dependency>

        <dependency>
            <groupId>io.github.qsy7.java.modules.browser.drivers</groupId>
            <artifactId>firefoxdriver</artifactId>
            <version>0.1.2</version>
        </dependency>

    </dependencies>
</project>

I tried changing versions Selenium in dependency but it didn't work.

  • Did you packed jar properly . may be you can unzip and verify all classes as exception is for unable to find few classes at run time – Anand Dwivedi Mar 20 '23 at 12:00
  • by default your dependencies are not part of the jar file. Use the jar-with-dependencies thing in maven. – f1sh Mar 20 '23 at 12:09

0 Answers0