drewr / postal

Clojure email support
MIT License
587 stars 85 forks source link

JDK 9+ compatibility: DataHandler missing #107

Open n2o opened 4 years ago

n2o commented 4 years ago

In JDK9+, DataHandler appears to be dropped. Therefore, an error is thrown:

#error {
 :cause javax.activation.DataHandler
 :via
 [{:type clojure.lang.Compiler$CompilerException
   :message Syntax error compiling at (postal/message.clj:1:1).
   :data #:clojure.error{:phase :compile-syntax-check, :line 1, :column 1, :source postal/message.clj}
   :at [clojure.lang.Compiler load Compiler.java 7648]}
  {:type java.lang.ClassNotFoundException
   :message javax.activation.DataHandler
   :at [java.net.URLClassLoader findClass URLClassLoader.java 436]}]}

To add a workaround, one can add this dependency to your project:

[com.sun.activation/javax.activation "1.2.0"]

Tested with AdoptOpenJDK 13

But this is just a workaround. Please update the corresponding lines in the code base.

Thanks!

dancek commented 4 years ago

Adding a dependency seems to also be the correct fix per JEP 320, though [javax.activation/javax.activation-api "1.2.0"] is suggested.

The JavaMail API still uses javax.activation.DataHandler legitimately.

caleb commented 4 years ago

So I shouldn't have issues with postal an JDK > 8 if I add that dependency?

Would a solution for postal be to include that library or to include a mention in the README?

dancek commented 4 years ago

We've been using the dependency and postal in production since May, and have had no issues.

I'm not sure if adding the dependency in postal itself causes issues in JDK 8 but it's what I would do.

wildwestrom commented 3 years ago

Even after adding [com.sun.activation/javax.activation "1.2.0"] as a dependency, when I call send-message I get this:

2. Unhandled clojure.lang.Compiler$CompilerException
   Error compiling postal/message.clj at (1:1)
   #:clojure.error{:phase :compile-syntax-check,
                   :line 1,
                   :column 1,
                   :source "postal/message.clj"}

1. Caused by java.lang.ClassNotFoundException
   javax.mail.Message
   [stacktrace....]
java --version
openjdk 16.0.2 2021-07-20
OpenJDK Runtime Environment Homebrew (build 16.0.2+0)
OpenJDK 64-Bit Server VM Homebrew (build 16.0.2+0, mixed mode, sharing)