dotemacs / pdfboxing

Nice wrapper of PDFBox in Clojure
BSD 3-Clause "New" or "Revised" License
177 stars 38 forks source link

ClassNotFoundException when using Java 9 #41

Closed jhemann closed 6 years ago

jhemann commented 6 years ago

OS: Linux Mint (Sarah)

Using this project.clj

(defproject myproject "0.1.0-SNAPSHOT"
  ...
  :dependencies [[org.clojure/clojure "1.9.0"]
                           [proto-repl "0.3.1"]
                           [pdfboxing "0.1.14-SNAPSHOT"]]) 

I get the following error under Java 9:

➜ myproject> lein -U repl nREPL server started on port 33000 on host 127.0.0.1 - nrepl://127.0.0.1:33000 REPL-y 0.3.7, nREPL 0.2.12 Clojure 1.9.0 Java HotSpot(TM) 64-Bit Server VM 9.0.4+11 Docs: (doc function-name-here) (find-doc "part-of-name-here") Source: (source function-name-here) Javadoc: (javadoc java-object-or-class-here) Exit: Control+D or (exit) or (quit) Results: Stored in vars 1, 2, 3, an exception in e

user=> (require '[pdfboxing.text :as text] :verbose) (clojure.core/load "/pdfboxing/text") (clojure.core/load "/pdfboxing/common")

CompilerException java.lang.ClassNotFoundException: javax.activation.FileDataSource, compiling:(pdfboxing/common.clj:1:1) (clojure.core/in-ns 'pdfboxing.common) (clojure.core/alias 'io 'clojure.java.io)

The issue seems to be that java.activation is deprecated in Java 9, see this issue.

I briefly tried downloading the JavaBeans Activation Framework and using the --add-modules argument to :jvm-opts in my profile, but gave up. Instead, when using pdfboxing I reverted to Java 8 via

➜ myproject> sudo update-alternatives --config java There are 2 choices for the alternative java (providing /usr/bin/java).

Selection Path Priority Status

  • 0 /usr/lib/jvm/java-9-oracle/bin/java 1091 auto mode 1 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode 2 /usr/lib/jvm/java-9-oracle/bin/java 1091 manual mode

Press to keep the current choice[*], or type selection number: 1 update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java to provide /usr/bin/java (java) in manual mode

Now, starting a REPL and bringing in pdfboxing works:

➜ myproject> lein -U repl
nREPL server started on port 39468 on host 127.0.0.1 - nrepl://127.0.0.1:39468 REPL-y 0.3.7, nREPL 0.2.12 Clojure 1.9.0 OpenJDK 64-Bit Server VM 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12 Docs: (doc function-name-here) (find-doc "part-of-name-here") Source: (source function-name-here) Javadoc: (javadoc java-object-or-class-here) Exit: Control+D or (exit) or (quit) Results: Stored in vars 1, 2, 3, an exception in e

user=> (require '[pdfboxing.text :as text] :verbose) (clojure.core/load "/pdfboxing/text") (clojure.core/load "/pdfboxing/common") (clojure.core/in-ns 'pdfboxing.common) (clojure.core/alias 'io 'clojure.java.io) (clojure.core/in-ns 'pdfboxing.text) (clojure.core/alias 'common 'pdfboxing.common) (clojure.core/in-ns 'user) (clojure.core/alias 'text 'pdfboxing.text) nil user=>

dotemacs commented 6 years ago

Thanks for this. Will look into it soon-ish...

agumonkey commented 6 years ago

Hi, I had the same issue, here's a working project.clj under:

;; CIDER 0.17.0snapshot (package: 20180219.1846), nREPL 0.2.12 ;; Clojure 1.9.0, Java 9.0.1 (oracle sdk under win10)

(defproject cloj "0.1.0-SNAPSHOT" :description "FIXME: write description" :url "http://example.com/FIXME" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :main cloj.core :jvm-opts ["-Xmx1g" "--add-modules" "java.activation"] :dependencies [[org.clojure/clojure "1.9.0"] [clj-time "0.14.2"] [pdfboxing "0.1.13"] [org.clojure/data.codec "0.1.1"]])

Disregard the Xmx1g, but the other jvm-options is what was required to make use of pdfboxing.

Hope it's of use for you (and thanks for your lib)

tirkarthi commented 6 years ago

I have added JDK9 to travis CI and fixed the error by replacing Preflight parser with PDF parser but I am not sure if there are any edge cases and the rationale behind using PreFlight parser. This passes the tests on JDK 9. But I don't any other cases that are handled but don't have tests.

tirkarthi commented 6 years ago

This PR https://github.com/dotemacs/pdfboxing/pull/21 would also remove this JDK9 specific error since it removes preflight as a dependency that uses javax components.

dotemacs commented 6 years ago

Hi @jhemann and @agumonkey

can you confirm that this change by @tirkarthi which I just merged solves the issue for you?

Thanks

agumonkey commented 6 years ago

I'd gladly try but where do I get the latest build jar ?

tirkarthi commented 6 years ago

I think you can do a clone and do lein install from the cloned directory to install it. I hope this project works with deps.edn which will be a good way to test this too.

dotemacs commented 6 years ago

Hey @agumonkey

you can do what @tirkarthi suggested, but if you haven't already, I just pushed: 0.1.14.1-SNAPSHOT for you to try.

Let me know how you get on.

dotemacs commented 6 years ago

I just tried it with Java 9 & Clojure 1.9.0.

I created deps.edn with this content:

{:deps
 {pdfboxing {:mvn/version "0.1.14.1-SNAPSHOT"}}}

And then I ran:

$ clj
Downloading: pdfboxing/pdfboxing/0.1.14.1-SNAPSHOT/maven-metadata.xml from https://clojars.org/repo/
Downloading: pdfboxing/pdfboxing/0.1.14.1-SNAPSHOT/pdfboxing-0.1.14.1-20180224.071331-1.pom from https://clojars.org/repo/
Downloading: pdfboxing/pdfboxing/0.1.14.1-SNAPSHOT/pdfboxing-0.1.14.1-20180224.071331-1.jar from https://clojars.org/repo/
Clojure 1.9.0
user=> (require '[pdfboxing.text :as text] :verbose)
(clojure.core/load "/pdfboxing/text")
(clojure.core/in-ns 'clojure.core.specs.alpha)
(clojure.core/alias 's 'clojure.spec.alpha)
(clojure.core/load "/pdfboxing/common")
(clojure.core/in-ns 'pdfboxing.common)
(clojure.core/alias 'io 'clojure.java.io)
(clojure.core/in-ns 'pdfboxing.text)
(clojure.core/alias 'common 'pdfboxing.common)
(clojure.core/in-ns 'user)
(clojure.core/alias 'text 'pdfboxing.text)
nil
user=> (text/extract "/Users/alex/dev/clojure/pdfboxing/test/pdfs/hello.pdf")
"Hello, this is pdfboxing.text\n"
agumonkey commented 6 years ago

i couldn't use deps.edn on my laptop right now; but using your latest 0.1.14.1-SNAPSHOT I could use you code without an issue on two random PDFs.

Thanks a lot

dotemacs commented 6 years ago

Thank you @jhemann @agumonkey for bringing this up and @tirkarthi for solving it.

I'll close this issue now.