gpt4 book ai didi

java - 错误 - 在 Spring Boot 项目中安装 Appium - Maven 依赖关系中断

转载 作者:行者123 更新时间:2023-12-05 05:35:53 28 4
gpt4 key购买 nike

我正在尝试在 Spring 引导项目上安装 appium - 根据此处 https://github.com/appium/java-client/blob/master/docs/Installing-the-project.md

当运行一个简单的脚本时,我得到了这个错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/internal/Requireat io.appium.java_client.remote.options.BaseOptions.setCapability(BaseOptions.java:144)at io.appium.java_client.remote.options.CanSetCapability.amend(CanSetCapability.java:30)at io.appium.java_client.remote.options.BaseOptions.setPlatformName(BaseOptions.java:86)at io.appium.java_client.android.options.UiAutomator2Options.setCommonOptions(UiAutomator2Options.java:222)at io.appium.java_client.android.options.UiAutomator2Options.(UiAutomator2Options.java:208)at com.aniview.testService.content.initAppium.main(initAppium.java:25)Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.internal.Requireat java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)... 6 more

我的脚本:

import io.appium.java_client.AppiumBy;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.options.UiAutomator2Options;
import org.openqa.selenium.WebElement;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
import java.util.concurrent.TimeUnit;



public class initAppium {

static AppiumDriver driver;

public static void main(String[] args) throws MalformedURLException, InterruptedException {
URL url = new URL("http://127.0.0.1:4723/wd/hub");
UiAutomator2Options options = new UiAutomator2Options()
.setDeviceName("emulator-5554 (sdk_gphone64_arm64 - Android 12)")
.setUdid("emulator-5554")
.setPlatformName("Android")
.setPlatformVersion("12")
.setChromedriverExecutable("/Users/x/node_modules/appium/node_modules/appium-chromedriver/chromedriver")
.setAppPackage("com.android.chrome")
.setAppActivity("com.google.android.apps.chrome.Main")
.setAutoWebview(true)
.eventTimings();

driver = new AppiumDriver(url, options);

System.out.println("Application started");
}

我的 pom.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
https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.aniview</groupId>
<artifactId>testService</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>testService</name>
<description>Web service for managing test executions</description>
<properties>
<java.version>18</java.version>
</properties>
<dependencies>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ini4j</groupId>
<artifactId>ini4j</artifactId>
<version>0.5.4</version>
</dependency>
<dependency>
<groupId>com.vaadin.external.google</groupId>
<artifactId>android-json</artifactId>
<version>0.0.20131108.vaadin1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.163</version>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-sheets</artifactId>
<version>v4-rev493-1.23.0</version>
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.33.0</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>com.google.guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client-jackson2</artifactId>
<version>1.32.1</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>25.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-gmail</artifactId>
<version>v1-rev33-1.20.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.mail/mail -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jsoup/jsoup -->
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.13.1</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client-java6</artifactId>
<version>1.23.0</version>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client-jetty</artifactId>
<version>1.23.0</version>
</dependency>
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>5.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.rabbitmq/amqp-client -->
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>5.14.2</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.1-jre</version>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>8.1.1</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.2.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.4.0</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

当我试图在一个新的项目上运行这个脚本时,只需要这个依赖:

  <dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>8.1.1</version>
</dependency>

它按预期工作并且没有出错。我知道 java-client 已经包含 selenium 库,但我试图删除它们,但它仍然出错。

我注意到的是:当我将所有依赖项添加到新项目时,除了 spring boot 依赖项之外,新项目运行良好。但是当我添加 spring 和父级(spring-boot-starter-parent)的 2 个依赖项时,它失败了。所以我猜这与 spring 依赖关系有关,可能特定于父依赖关系。

我该如何解决?

环境 - Mac、M1 pro、Intelij、Maven、Java 18

谢谢。

最佳答案

已解决

我发现 <parent>标签覆盖了依赖项(在我的例子中,“spring-boot-starter-parent”覆盖了 Selenium jar )所以我导航到 ~/.m2/repository/org/springframework/boot/spring-boot-dependencies/2.6.3/spring-boot-dependencies-2.6.3.pom改变了那些: 4.4.0 2.64.0

实际上,我可以将我的 spring-boot 更新到 2.7.2,它应该也能正常工作。

关于java - 错误 - 在 Spring Boot 项目中安装 Appium - Maven 依赖关系中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73405070/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com