The problem of [: Unknown HttpClient factory jdk-http-client] has appeared again when i repacke selenium.

21 views
Skip to first unread message

yu xinagjie

unread,
Jun 28, 2024, 12:04:18 PM (5 days ago) Jun 28
to Selenium Users
What can I do to solve this problem ? Please help me. Thank you.

What happened?

I have a java project with dependencies

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

Environment

JDK17 Windows 11 Edgebrowser: 106.0.1370.86

I packaged it using the following method to avoid dependency conflicts in another project.

<groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>3.2.4</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <relocations> <relocation> <pattern>org.openqa.selenium</pattern> <shadedPattern>link-download.org.openqa.selenium</shadedPattern> </relocation> </relocations> </configuration> </execution> </executions>

My main function to excute.

public void downloadFileThroughUrl() throws InterruptedException { System.setProperty("webdriver.edge.driver", System.getProperty("user.dir") + File.separator + "MicrosoftWebDriver.exe"); EdgeOptions edgeOptions = new EdgeOptions(); edgeOptions.addArguments("--headless"); Map<String, Object> settings = new HashMap<>(); settings.put("download.default_directory", System.getProperty("user.dir")); settings.put("plugins.always_open_pdf_externally", true); settings.put("download.prompt_for_download",false); settings.put("profile.default_content_settings.popups",0); settings.put("safebrowsing.enabled",true); WebDriver driver = null; try { edgeOptions.setExperimentalOption("prefs",settings); driver = new EdgeDriver(edgeOptions); driver.get("your valid download link"); Thread.sleep(10000); System.out.println("Download successfully."); } catch (Exception e) { e.printStackTrace(); } finally { if(driver != null){ driver.quit(); } } }

Jar file
link-download-1.0-SNAPSHOT.zip

How can we reproduce the issue?
In a new project, depending on this JAR file, and calling it using the following method: DownloadFileByLink downloadFileByLink = new DownloadFileByLink(); downloadFileByLink.downloadFileThroughUrl(); Will appear [[java.lang.IllegalArgumentException: Unknown HttpClient factory jdk-http-client] when creating new driver.
Relevant log output
Caused by: java.lang.IllegalArgumentException: Unknown HttpClient factory jdk-http-client at link-download.org.openqa.selenium.remote.http.HttpClient$Factory.create(HttpClient.java:57) at link-download.org.openqa.selenium.remote.http.HttpClient$Factory.createDefault(HttpClient.java:74) at link-download.org.openqa.selenium.remote.HttpCommandExecutor$DefaultClientFactoryHolder.<clinit>(HttpCommandExecutor.java:56) ... 17 more

Operating System

Windows 11

Selenium version

4.22.0

What are the browser(s) and version(s) where you see this issue?

Edgebrowser: 106.0.1370.86

What are the browser driver(s) and version(s) where you see this issue?

EdgeDriver

Are you using Selenium Grid?

NO

Krishnan Mahadevan

unread,
Jun 28, 2024, 12:27:48 PM (5 days ago) Jun 28
to seleniu...@googlegroups.com
The below pom file should basically fix your issue.


I have configured my pom file to ensure that it also adds up a main class to the manifest file, so that I can do a “java -jar” and be able to run the executable jar.


<?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>com.rationaleemotions</groupId> <artifactId>exploding_jars</artifactId> <version>1.0-SNAPSHOT</version> <name>exploding_jars</name> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>11</maven.compiler.source> <maven.compiler.target>11</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>4.22.0</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>3.2.4</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <relocations> <relocation> <pattern>org.openqa.selenium</pattern> <shadedPattern>shaded.org.openqa.selenium</shadedPattern> </relocation> </relocations> </configuration> </execution> </executions> <configuration> <transformers> <!-- Refers to the main class that should be executed when using java -jar --> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>com.rationaleemotions.App</mainClass> </transformer> <!-- This fixes the META-INF/services file to refer to the proper shaded package name. This is very important because the http client implementation is wired in by Selenium using Service Loading --> <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/> </transformers> </configuration> </plugin> </plugins> </build> </project>



Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/a7c2d1a2-4600-4294-89e1-a921c51e64d0n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages