Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exec binary does not work on Java 9+ #133

Closed
totakke opened this issue Jun 22, 2018 · 9 comments
Closed

exec binary does not work on Java 9+ #133

totakke opened this issue Jun 22, 2018 · 9 comments
Labels

Comments

@totakke
Copy link
Member

totakke commented Jun 22, 2018

$ lein bin
...
Creating standalone executable: /path/to/cljam/target/cljam

# 1.8
$ java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
$ target/cljam version
0.5.2-SNAPSHOT

# 9
$ java -version
java version "9.0.1"
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)
$ target/cljam version
Exception in thread "main" java.lang.ExceptionInInitializerError
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:375)
        at clojure.lang.RT.classForName(RT.java:2168)
        at clojure.lang.RT.classForName(RT.java:2177)
        at clojure.lang.RT.loadClassForName(RT.java:2196)
        at clojure.lang.RT.load(RT.java:443)
        at clojure.lang.RT.load(RT.java:419)
        at clojure.core$load$fn__5677.invoke(core.clj:5893)
        at clojure.core$load.invokeStatic(core.clj:5892)

# 10
$ java -version
java 10.0.1 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
$ target/cljam -h
Exception in thread "main" java.lang.ExceptionInInitializerError
        at java.base/java.lang.Class.forName0(Native Method)
        ... (same error)
@totakke totakke added the bug label Jun 22, 2018
@alumi
Copy link
Member

alumi commented Jun 22, 2018

FWIW, I couldn't reproduce the bug in CI and my local env (macOS 10.13.5, Java 9.0.1 & 1.8.0_131) 🤔

https://github.com/chrovis/cljam/compare/fix/upgrade-deps#diff-354f30a63fb0907d4ad57269548329e3R25

diff --git .travis.yml .travis.yml
index 00148b5..104dc56 100644
--- .travis.yml
+++ .travis.yml
@@ -4,16 +4,25 @@ cache:
   directories:
     - $HOME/.m2
 jdk:
+  - oraclejdk10
   - oraclejdk9
   - oraclejdk8
+  - openjdk11
+  - openjdk10
+  - openjdk9
   - openjdk8
-  - openjdk7
 env:
   matrix:
-    - VERSION='1.7'
     - VERSION='1.8'
     - VERSION='1.9'
-script: lein with-profile dev,$VERSION test
+    - VERSION='1.10'
+before_install:
+  - if [ -f "${JAVA_HOME}/lib/security/cacerts" -a -w  "${JAVA_HOME}/lib/security/cacerts" ]; then rm "${JAVA_HOME}/lib/security/cacerts" && ln -s /etc/ssl/certs/java/cacerts "${JAVA_HOME}/lib/security/cacerts"; fi;
+script:
+    - lein with-profile dev,$VERSION test
+    - lein bin
+    - java -version
+    - target/cljam version
 jobs:
   include:
     - stage: coverage

https://travis-ci.org/chrovis/cljam/builds/395312419

@totakke
Copy link
Member Author

totakke commented Jun 22, 2018

On my environment (master branch), Clojure version also seems to affect this problem.

  • Clojure 1.8 (lein bin) + Java 1.8 -> work 😄
  • Clojure 1.8 (lein bin) + Java 9+ -> error 😖
  • Clojure 1.7 (lein with-profile +1.7 bin) + Java 1.8 -> work 😄
  • Clojure 1.7 (lein with-profile +1.7 bin) + Java 9+ -> error 😖
  • Clojure 1.9 (lein with-profile +1.9 bin) + Java 1.8 -> work 😄
  • Clojure 1.9 (lein with-profile +1.9 bin) + Java 9+ -> work 😄

but these patterns are tested the above CI config. umm...

@alumi
Copy link
Member

alumi commented Jun 22, 2018

Oops! I forgot to specify Clojure verisons in the CI... 😵

lein bin => lein with-profile dev,$VERSION bin

It's now failing on Clojure 1.8 with Java 9+
https://travis-ci.org/chrovis/cljam/builds/395327461

@alumi
Copy link
Member

alumi commented Jun 22, 2018

Maybe this is related to CLJ-2077

clojure.core

(defmacro ^:private when-class [class-name & body]
  `(try
     (Class/forName ^String ~class-name)
     ~@body
     (catch ClassNotFoundException _#)))

(when-class "java.sql.Timestamp"
  (load "instant"))

@totakke
Copy link
Member Author

totakke commented Jun 22, 2018

That may be right. Leiningen <2.8 also had the same problem.

:uberjar {:dependencies [[org.clojure/clojure "1.9.0"]

just resolves this issue.

@alumi
Copy link
Member

alumi commented Jun 22, 2018

or we can use Clojure 1.8 with Java 9+ by setting --add-modules option and unset the bootclasspath

diff --git project.clj project.clj
index 7cfd6a1..e734624 100644
--- project.clj
+++ project.clj
@@ -30,7 +30,11 @@
                    :main ^:skip-aot cljam.tools.main
                    :global-vars {*warn-on-reflection* true}}
              :1.7 {:dependencies [[org.clojure/clojure "1.7.0"]]}
-             :1.8 {:dependencies [[org.clojure/clojure "1.8.0"]]}
+             :1.8 {:dependencies [[org.clojure/clojure "1.8.0"]]
+                   :bin {:jvm-opts ~(if (<= 9 (Integer/parseInt (re-find #"^\d+" (System/getProperty "java.version"))))
+                                      ["--add-modules" "java.sql"]
+                                      [])
+                         :bootclasspath ~(> 9 (Integer/parseInt (re-find #"^\d+" (System/getProperty "java.version"))))}}
              :1.9 {:dependencies [[org.clojure/clojure "1.9.0"]]}
              :1.10 {:dependencies [[org.clojure/clojure "1.10.0-alpha4"]]}
              :uberjar {:dependencies [[org.clojure/clojure "1.9.0"]

@totakke
Copy link
Member Author

totakke commented Jun 22, 2018

Yes, but that is more than necessary. It is simple and enough to create working binary with clojure 1.9.

@alumi
Copy link
Member

alumi commented Jun 22, 2018

I agree 😃
I opened PR #134 using Clojure 1.9.
Thanks.

@totakke
Copy link
Member Author

totakke commented Jun 22, 2018

@alumi Thanks!

@totakke totakke closed this as completed Jun 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants