1

I am building a Java Selenium standalone application using Java11 in Eclipse 2018-12 but my builds fail:

java.lang.module.FindException: Unable to derive module descriptor for \selenium-server-standalone-3.141.59.jar

I was looking into how module dependencies are defined in the latest version of java as I have been using only version 8 so far.

module-info.java:

module main {
    requires org.openqa.selenium.core;
}

mainClass:

package main;

import org.openqa.selenium.WebDriver;

public class DownloadDocuments {

    public static void main(String[] args) {
        System.out.println("hello!");
        WebDriver driver;
    }

}

Are there any additional configurations steps needed when working with modules?

The stacktrace

java.lang.module.FindException: Unable to derive module descriptor for \selenium-server-standalone-3.141.59.jar
    at java.base/jdk.internal.module.ModulePath.readJar(ModulePath.java:647)
    at java.base/jdk.internal.module.ModulePath.readModule(ModulePath.java:330)
    at java.base/jdk.internal.module.ModulePath.scan(ModulePath.java:236)
    at java.base/jdk.internal.module.ModulePath.scanNextEntry(ModulePath.java:189)
    at java.base/jdk.internal.module.ModulePath.findAll(ModulePath.java:165)
    at java.base/java.lang.module.ModuleFinder$2.lambda$findAll$2(ModuleFinder.java:368)
    at java.lang.module.ModuleFinder$2$$Lambda$22.00000000DB437580.apply(Unknown Source)
    at java.base/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:271)
    at java.base/java.util.AbstractList$RandomAccessSpliterator.forEachRemaining(AbstractList.java:720)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:499)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:489)
    at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
    at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:241)
    at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
    at java.base/java.lang.module.ModuleFinder$2.findAll(ModuleFinder.java:369)
    at java.base/java.lang.module.Resolver.findAll(Resolver.java:841)
    at java.base/java.lang.module.Resolver.bind(Resolver.java:223)
    at java.base/java.lang.module.Configuration.resolveAndBind(Configuration.java:304)
    at java.base/java.lang.module.ModuleDescriptor$1.resolveAndBind(ModuleDescriptor.java:2735)
    at java.base/jdk.internal.module.ModuleBootstrap.boot(ModuleBootstrap.java:337)
    at java.base/java.lang.ClassLoader.initializeClassLoaders(ClassLoader.java:217)
    at java.base/java.lang.Thread.initialize(Thread.java:422)
    at java.base/java.lang.Thread.<init>(Thread.java:153)
Caused by: java.lang.module.InvalidModuleDescriptorException: Provider class org.eclipse.jetty.http.Http1FieldPreEncoder not in module
    at java.base/jdk.internal.module.ModulePath.deriveModuleDescriptor(ModulePath.java:554)
    at java.base/jdk.internal.module.ModulePath.readJar(ModulePath.java:643)
    ... 23 more
Naman
  • 27,789
  • 26
  • 218
  • 353
Marek Andreansky
  • 297
  • 1
  • 6
  • 19
  • Is there more to the stack trace? Does it have any “Caused by” sections? – VGR Dec 27 '18 at 22:31
  • I resolved it by moving my dependencies from the modulepath to the classpath. Not sure if that is the correct solution, and if I should add this as an answer to my question. – Marek Andreansky Dec 27 '18 at 23:10
  • It’s probably fine. By using the classpath instead of the modulepath, you are telling Java to ignore modules and just treat every .jar file as a simple archive. I admit, though, I am curious as to why the Selenium .jar could not be treated as an automatic module… – VGR Dec 28 '18 at 14:59
  • @VGR I've updated the question with a stacktrace, I am curious as well. – Marek Andreansky Dec 29 '18 at 11:53
  • Strange. That .jar (which I obtained from [here](https://selenium-release.storage.googleapis.com/3.141/selenium-server-standalone-3.141.59.jar)) is a multi-release jar, so clearly it was intended to support Java 9. When I do `jar -d -f selenium-server-standalone-3.141.59.jar --release 9`, I see no use of service providers at all. – VGR Dec 30 '18 at 16:19

4 Answers4

3

For me, it was that i only had to move the selenium.jar in my build path in libraries from modulepath to classpath. hope it helps.

Ayush
  • 31
  • 1
  • 5
2

see here https://github.com/SeleniumHQ/selenium/wiki/Building-WebDriver

The Java JDK 8 (note that versions 9 & 10 are not currently supported for building Selenium). Download it from Oracle's site if it's not already on your computer.

murali selenium
  • 3,847
  • 2
  • 11
  • 20
  • Thanks for the answer, I have Java8 installed, but wanted to use the latest version for a new project to benefit from the improvements it has. – Marek Andreansky Dec 27 '18 at 18:06
1

This is due to a mistake in the .jar file. It contains a META-INF/services/org.eclipse.jetty.http.HttpFieldPreEncoder entry, which, according to the jar service provider interface specification, must contain the name of a class in the same .jar file which implements the interface org.eclipse.jetty.http.HttpFieldPreEncoder.

But, as the exception states, that service descriptor file contains org.eclipse.jetty.http.Http1FieldPreEncoder, a class which does not exist in the .jar file.

There is, however, a org.seleniumhq.jetty9.http.Http1FieldPreEncoder class in the .jar.

The easiest way to fix this is:

  • Extract the entire .jar to a temporary directory.
  • Change META-INF/services/org.eclipse.jetty.http.HttpFieldPreEncoder so it contains the single line org.seleniumhq.jetty9.http.Http1FieldPreEncoder.
  • Create a new .jar file from the changed content.

If you’re not in Windows, you can do it on the command line:

mkdir -p META-INF/services
echo org.seleniumhq.jetty9.http.Http1FieldPreEncoder > META-INF/services/org.eclipse.jetty.http.HttpFieldPreEncoder
zip -u -m selenium-server-standalone-3.141.59.jar META-INF/services/org.eclipse.jetty.http.HttpFieldPreEncoder
rm -r META-INF
VGR
  • 40,506
  • 4
  • 48
  • 63
  • Thanks for the reply @VGR! I opened a bug report for Selenium, pointing the developers to your reply. Hopefully it is something that can be fixed upstream. – Marek Andreansky Dec 31 '18 at 12:44
0

Encountered the same problem, defining all the jars in the classpath will serve the purpose.