Fork me on GitHub
#graalvm
<
2020-02-26
>
Alex Miller (Clojure team)15:02:38

feel the tingle in the air?

✔️ 24
maybenot18:02:23

Hi there. I'm trying to compile simple code with lein native-image which is using com.jcraft.jsch.JSch and got following error

Error: No instances of .Inet4Address are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use -H:+TraceClassInitialization.
Detailed message:
Trace: Object was reached by 
	reading field com.jcraft.jsch.PortWatcher.anyLocalAddress 
How can I prevent this? I tried --initialize-at-run-time with anyLocalAddress but it didn't help. Maybe someone compiled Jsch before? The code looks like this
(ns binssh.core
  (:import (com.jcraft.jsch JSch))
  (:gen-class))


(defn -main
  [& args]
  (let [[user host keyname & other] args
        ssh (JSch.)
        port 22]
    (let [sess (.getSession ssh user host port)]
      (.setPortForwardingL sess 8842 "localhost" 8888)
      (.connect sess))))

borkdude18:02:26

@romantsopin which graalvm version are you using?

borkdude18:02:32

@romantsopin I think this project might be using JSch: https://github.com/epiccastle/spire - maybe you can look at that

maybenot18:02:50

GraalVM CE 20.0.0

borkdude18:02:05

which java version, 8 or 11?

maybenot18:02:16

it's 13. This may cause problems?

borkdude18:02:40

13 is not a java version that graal supports, it's either 8 or 11

borkdude18:02:58

anyway, try with 19.3.1-java8

maybenot18:02:17

Will do, thank you!

borkdude18:02:41

also, take care that you don't get reflection, so put *warn-on-reflection* to true

maybenot18:02:01

I took option --initialize-at-run-time=com.jcraft.jsch.PortWatcher from epiccastle/spire and seems like it's working

maybenot18:02:18

this is awesome, thanks @borkdude!

👍 4
maybenot18:02:10

Also maybe you have a good reference which explains all this flags in detail and how do exactly they work?

borkdude18:02:37

we have some docs here: https://github.com/lread/clj-graal-docs welcome to contribute if you have anything to add!

👍 4
zilti20:02:20

borkdude, any reason why java8 instead of java11?

borkdude20:02:39

@zilti I've had some issues with jdk11, so in case of problems it's good to see if java8 behaves differently