开发者

Making an executable jar that evals Clojure strings

开发者 https://www.devze.com 2023-04-13 03:05 出处:网络
I\'m building a Java app that loads Clojure files.I\'m having trouble making a single executable jar.I\'m using One-Jar开发者_JS百科, but I get an exception when I try to run the jar file:

I'm building a Java app that loads Clojure files. I'm having trouble making a single executable jar. I'm using One-Jar开发者_JS百科, but I get an exception when I try to run the jar file:

Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at com.simontuffs.onejar.Boot.run(Boot.java:340)
    at com.simontuffs.onejar.Boot.main(Boot.java:166)
Caused by: java.lang.ExceptionInInitializerError
    at com.ziroby.clojure.App.main(App.java:14)
    ... 6 more
Caused by: java.lang.NullPointerException
    at clojure.lang.RT.lastModified(RT.java:374)
    at clojure.lang.RT.load(RT.java:408)
    at clojure.lang.RT.load(RT.java:398)
    at clojure.lang.RT.doInit(RT.java:434)
    at clojure.lang.RT.<clinit>(RT.java:316)
... 7 more

When I look at the line that's causing it, it seems to be trying to get jar information for the relative class files:

    return ((JarURLConnection) url.openConnection()).getJarFile()
           .getEntry(libfile).getTime();

I think this means that it's trying to get jar information for an embedded jar, which doesn't actually exist on the file system. It's looking at that to see if it needs to recompile a file (like common/core.clj).

Am I doing something wrong? Is there some other way to create an executable jar (with dependencies) without confusing Clojure?


I have come to the conclusion that this is a bug in Clojure. I am able to add a single null check (just before the .getTime() call), and it works correctly. I've entered a bug in Clojure's Jira: http://dev.clojure.org/jira/browse/CLJ-971

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号