appropriate / docker-jetty

Formerly the location of the Docker official image for Jetty
https://registry.hub.docker.com/_/jetty/
46 stars 46 forks source link

Mail library included in jetty-jre11 is not compatible with JDK11 #108

Closed geoffreyharding closed 4 years ago

geoffreyharding commented 5 years ago

There is a bug in the jetty:9.4-jre11 docker image.

The following runtime error is thrown when using javax.mail.internet.MimeMessage:

java.lang.NoClassDefFoundError: javax/activation/DataSource

javax.activation was removed from the JDK in Java 11. Adding javax.activation to the WAR file doesn't fix the runtime bug. The reason is that Jetty is bundled with its own mail, which overrides the one in the WAR.

The solution is to delete the mail from the Jetty dockerfile:

USER root
RUN rm -r /usr/local/jetty/lib/mail
USER jetty

This blog post describes the problem in more detail: https://www.databasesandlife.com/activation-error-jetty-javamail-java11/

gregw commented 5 years ago

@janbartel what did we do to fix this?

janbartel commented 5 years ago

@gregw in jetty-9.4 we have the mail.mod module, which puts javax.mail.glassfish-1.4.1.v201005082020.jar onto the container classpath. That jar contains both the javax.mail apis and the impl. This is tested and working in jdk-11 and beyond.

For jetty-10.0 we have removed the mail.mod module altogether. If users wish to use a javax.mail service the they need to provide their own jar/s, preferably by making their own mail mod file.

See also jetty issue https://github.com/eclipse/jetty.project/issues/2960.

bcmedeiros commented 4 years ago

Any chances of having some Jetty 10 preview images? I really don't have a workaround without a baseline Docker image that supports Java 11 and doesn't break email.

bcmedeiros commented 4 years ago

Workaround for now:

FROM jetty:9.4-jre11
...
# workaround for https://github.com/appropriate/docker-jetty/issues/108
USER root
RUN rm -rf /usr/local/jetty/lib/mail
USER jetty
gregw commented 4 years ago

@brunojcm we should be doing an jetty-10-alpha1 release next week, so I'll try to get a docker image going as well.... feel free to hassle me if I forget!

bcmedeiros commented 4 years ago

@gregw, thanks for the update! Let me know if you need some help testing.

vmassol commented 4 years ago

@gregw in jetty-9.4 we have the mail.mod module, which puts javax.mail.glassfish-1.4.1.v201005082020.jar onto the container classpath. That jar contains both the javax.mail apis and the impl. This is tested and working in jdk-11 and beyond.

@janbartel Hi. You seem to be saying that Jetty 9.4 fixes the problem on JDK11+. However on the XWiki project we're using the Jetty docker image 9 tag (which corresponds to 9.4.27 as of today). Yet we still have the issue, see https://github.com/eclipse/jetty.project/issues/2960#issuecomment-593880571

11:16:11.618 [tc-okhttp-stream-1150574999] INFO  o.x.t.d.i.j.s.ServletContainerExecutor - STDOUT: Caused by: java.lang.NoClassDefFoundError: javax/activation/DataSource
11:16:11.618 [tc-okhttp-stream-1150574999] INFO  o.x.t.d.i.j.s.ServletContainerExecutor - STDOUT:   at com.xpn.xwiki.plugin.mailsender.MailSenderPlugin.createMimeMessage(MailSenderPlugin.java:229)
...
Caused by: java.lang.ClassNotFoundException: javax.activation.DataSource
11:16:11.634 [tc-okhttp-stream-1150574999] INFO  o.x.t.d.i.j.s.ServletContainerExecutor - STDOUT:   at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
11:16:11.634 [tc-okhttp-stream-1150574999] INFO  o.x.t.d.i.j.s.ServletContainerExecutor - STDOUT:   at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
11:16:11.634 [tc-okhttp-stream-1150574999] INFO  o.x.t.d.i.j.s.ServletContainerExecutor - STDOUT:   at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
11:16:11.635 [tc-okhttp-stream-1150574999] INFO  o.x.t.d.i.j.s.ServletContainerExecutor - STDOUT:   ... 113 common frames omitted

Note that we bundle jakarta.activation-1.2.1.jar in XWiki's WEB-INF/lib directory.

So, is Jetty 9.4 supposed to fix the problem? If so I wonder why it's not working for us. Any idea?

Thanks!

vmassol commented 4 years ago

Found a solution thanks to a message from @janbartel :)

I've put the following in our jetty-web.xml:

  <Call name="prependSystemClass">
    <Arg>-javax.mail.</Arg>
  </Call>
  <Call name="prependServerClass">
    <Arg>javax.mail.</Arg>
  </Call>

And it worked :)

joakime commented 4 years ago

@vmassol that's old school syntax (and deprecated)

Use ...

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
  <Get name="systemClasspathPattern">
    <Call name="add"><Arg>-javax.mail.</Arg></Call>
  </Get>
  <Get name="serverClasspathPattern">
    <Call name="add"><Arg>javax.mail.</Arg></Call>
  </Get>
vmassol commented 4 years ago

@joakime Thanks a lot! I was too happy to have found a working workaround that I didn't notice it ;)

joakime commented 4 years ago

This issue has been moved to the new Official Eclipse Jetty Docker repository.

See https://github.com/eclipse/jetty.docker/issues/10