ApacheHttpClient$Factory throwing java.lang.NoClassDefFoundError Exception

偶尔善良 提交于 2020-03-26 03:53:40

问题


I'm trying to run a sample test via Appium on BrowserStack. All the code comes from BrowserStack and uses their sample .ipa file. The following is the log for the error that I'm receiving.

Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/remote/internal/ApacheHttpClient$Factory
at io.appium.java_client.remote.AppiumCommandExecutor.<init>(AppiumCommandExecutor.java:55)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:131)
at io.appium.java_client.ios.IOSDriver.<init>(IOSDriver.java:82)
at BrowserStackIOS.main(BrowserStackIOS.java:28)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.remote.internal.ApacheHttpClient$Factory
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    ... 4 more

Here is the line of code that is being referenced at line 28

IOSDriver<IOSElement> driver = new IOSDriver<IOSElement>(new URL("http://"+userName+":"+accessKey+"@hub-cloud.browserstack.com/wd/hub"), caps);

In addition to that, I'm using maven. I got my dependencies from https://search.maven.org/search?q=g:io.appium%20AND%20a:java-client

Bindings (for java) from https://selenium.dev/downloads/

Regarding the Bindngs, I'm not sure if I installed them correctly.I extracted the zip file and added the .jar files located in the libs folder to my dependencies. This is a screenshot https://prnt.sc/qoqwzf This a screenshot of the selenium/remote/internal folder https://prnt.sc/qoqxh8

Notes: Never used maven before so I'll just include additional notes: I receive a build success when I run mvn install -U I'm only receiving that error when I try to build my project.

What I've done to try and resolve the error: I've updated all selenium dependencies to 4.0.0-alpha-4 using https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java/4.0.0-alpha-4

I tried editing my pom.xml by: Adding the web driver dependency

 <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-remote-driver</artifactId>
            <version>4.0.0-alpha-4</version>
        </dependency>

Adding the Safari web driver dependency

       <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-safari-driver</artifactId>
            <version>4.0.0-alpha-4</version>
        </dependency>

Additional notes: My POM.xml looks exactly like the one given in https://search.maven.org/remotecontent?filepath=io/appium/java-client/7.3.0/java-client-7.3.0.pom with a few additional dependencies, which I've noted above.

The following are the imports that I'm requesting in my main class

import java.net.URL;
import java.util.List;
import java.net.MalformedURLException;

import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;

import io.appium.java_client.MobileBy;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.ios.IOSElement;

I also edited the maven compiler source to 7 as per the error I was receiving requesting that I do so due to compiler source 5 being incompatible with what I was running.

<properties>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
    </properties>

The following is the beginning of my pom, which I edited, not sure if this could be an issue or not but I figured someone else would know.

<modelVersion>4.0.0</modelVersion>
    <groupId>-</groupId>
    <artifactId>First</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>java-client</name>
    <description>Java client for Appium Mobile Webdriver</description>
    <url>http://appium.io</url>

If any additional information is needed please let me know. I'm currently in the process of adjusting my environment so there have been various errors that have come up and gotten resolved. This is the only one I haven't been able to really get my head around.

Edit: My Appium dependency is

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

All my current dependencies

<dependencies>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>4.0.0-alpha-4</version>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
                <artifactId>*</artifactId>
                <groupId>com.google.code.gson</groupId>
            </exclusion>
            <exclusion>
                <artifactId>htmlunit-driver</artifactId>
                <groupId>*</groupId>
            </exclusion>
            <exclusion>
                <artifactId>*</artifactId>
                <groupId>net.sourceforge.htmlunit</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-support</artifactId>
        <version>4.0.0-alpha-4</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-api</artifactId>
        <version>4.0.0-alpha-4</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-safari-driver</artifactId>
        <version>4.0.0-alpha-4</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-remote-driver</artifactId>
        <version>4.0.0-alpha-4</version>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.5</version>
        <scope>compile</scope>
    </dependency>

Deleted

org.apache.httpcomponents httpclient 4.5.9 compile Deleted

    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>3.2.12</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>commons-validator</groupId>
        <artifactId>commons-validator</artifactId>
        <version>1.6</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.9</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.6</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>5.1.8.RELEASE</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjweaver</artifactId>
        <version>1.9.4</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.26</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>io.appium</groupId>
        <artifactId>java-client</artifactId>
        <version>4.1.2</version>
    </dependency>
    <!-- Thanks for using https://jar-download.com -->
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.5.10</version>
    </dependency>
</dependencies>

回答1:


Root cause of this problem is Jar hell

Dependencies for selenium 4.0.0-alpha-4 depends on Appium Java Client 7.1.0.

You're getting errors due to the conflict between dependencies you have declared in your pom.xml file and transitive dependencies of the Appium Java Client. If you will change Appium Java Client 4.1.2 to Appium Java Client 7.1.0 will solve the problem.



来源:https://stackoverflow.com/questions/59777847/apachehttpclientfactory-throwing-java-lang-noclassdeffounderror-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!