Skip to content
This repository has been archived by the owner on Jun 29, 2020. It is now read-only.

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

Closed
geoffreyharding opened this issue Jul 19, 2019 · 11 comments
Closed

Comments

@geoffreyharding
Copy link

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
Copy link
Contributor

gregw commented Jul 19, 2019

@janbartel what did we do to fix this?

@janbartel
Copy link

@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 jetty/jetty.project#2960.

@bcmedeiros
Copy link

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
Copy link

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
Copy link
Contributor

gregw commented Oct 11, 2019

@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
Copy link

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

@vmassol
Copy link

vmassol commented Mar 3, 2020

@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 jetty/jetty.project#2960 (comment)

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
Copy link

vmassol commented Mar 3, 2020

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
Copy link

joakime commented Mar 3, 2020

@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
Copy link

vmassol commented Mar 3, 2020

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

@joakime
Copy link

joakime commented Jun 8, 2020

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

See jetty/jetty.docker#10

@md5 md5 closed this as completed Jun 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants