Using Java to do a Selenium crawler project, can crawl some of the information I need to the server I had no problem using Selenium crawler locally, then I tried to deploy it to Linux server and start it up. Locally, I packaged it into jar with idea and started it on linux with java -jar command, but every time I called the crawler service after starting, I got the following exception

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: org/openqa/selenium/interactions/Coordinates] with root cause

java.lang.ClassNotFoundException: org.openqa.selenium.interactions.Coordinates
        at java.net.URLClassLoader.findClass(URLClassLoader.java:387) ~[na:1.8.0_401]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:418) ~[na:1.8.0_401]
        at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:151) ~[autoCrawler-0.0.1-SNAPSHOT.jar:na]

Here's my Selenium configuration

        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.addArguments("--headless");
        chromeOptions.addArguments("--disable-gpu");
        chromeOptions.addArguments("--no-sandbox");
        chromeOptions.addArguments("--disable-dev-shm-usage");
        chromeOptions.addArguments("lang=zh_CN.UTF-8");
        chromeOptions.addArguments("window-size=1920x1080"); 

On Linux, Chrome is at version 122.0.6261.111, chromedriver is at version 122.0.6261.94, and Linux is using JDK 1.8 I have been searching for a long time but can not solve this problem, does anyone know to help me to see what is going on? I really don't get it, to be honest

        <!-- selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.6.0</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-api</artifactId>
            <version>4.6.0</version>
        </dependency>
1

There are 1 best solutions below

1
Rolin On

我的selenium引入的依赖是

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-api</artifactId>
            <version>3.14.0</version>
        </dependency>

They've got the dependency wrong