While migrating one of our projects to Java 9(build 9+181), I am facing a peculiar problem what looks like an incorrect implementation in some libr
From the sample project I was able to fix the compilation issue. There were 2 exceptions in com.SomeService#run
method. There were missing modules in your module-info.java, once you add these the code should compile.
requires dropwizard.jersey;
requires dropwizard.jetty;
JerseyEnvironment
comes from io.dropwizard:dropwizard-jersey:1.1.0
ServletEnvironment
comes from io.dropwizard:dropwizard-jetty:1.1.0
Since they are different jars, they export different modules. Hence, the requires needs to be explicitly added. Your code works fine without module-info.java because at that time module system is not used.
I found the fix by doing the below, method mentioned in comments:
@Override
public void run(SomeServiceConfig config, Environment environment) throws Exception {
Injector injector = Guice.createInjector(new SomeServiceModule());
// Fix: Extract to variable to find Type of jersey and then find the module to add under requires
JerseyEnvironment jersey = environment.jersey();
jersey.register(injector.getInstance(SomeResource.class));
// Fix 2: Same method as Fix 1
ServletEnvironment servlets = environment.servlets();
servlets.addFilter("Some-Filter", SomeFilter.class);
}