I've also seen a case of that(context classloader changing so that calling clojure will work) here [1], if anyone's into Minecraft bukkit server tests this would be somewhat easy to understand if you can test it:
[1] - https://github.com/CmdrDats/clj-minecraft/blob/master/javasrc/cljminecraft/ClojurePlugin.java and the sister file: https://github.com/CmdrDats/clj-minecraft/blob/master/javasrc/cljminecraft/BasePlugin.java On Fri, Jan 25, 2013 at 3:37 PM, Francesco Bellomi < francesco.bell...@gmail.com> wrote: > I've solved my specific instance of this problem, I post here the details > in the hope that the solution has a more general validity. > > It seems that clojure.lang.RT gets confused when it is initialized (ie. > <clinit> is called) and the classloader used to load the class itself is > different from the current thread's context classloader. > > If I do: > > Thread.currentThread().**setContextClassLoader(this.** > getClass.getClassLoader) > > just before making the call that cause Clojure runtime to be loaded and > initialized, the error disappears. > > Francesco > > > > > On Thursday, January 24, 2013 2:44:21 PM UTC+1, Francesco Bellomi wrote: >> >> (I repost this message because the original post I made yesterday seems >> to have been rejected by googlegroups -- I have not received it and it is >> not available online. >> Sorry if this will result in a double post for some users.) >> >> Hi all, >> >> I'm writing a Scala library (currently alpha) to simplify the use of >> Datomic (http://www.datomic.com) from Scala: >> https://github.com/fbellomi/**da**tomic-scala<https://github.com/fbellomi/datomic-scala> >> >> I would like to make use of Scala compile-time macros in order to >> statically type-check Datomic queries against a live database schema. >> I need to call Datomic API from within the Scala compiler's macro >> expansion stage, but it turns out that Clojure runtime fails to initialize >> within that stage. >> >> A simple evaluation such as: >> >> clojure.lang.RT.T >> >> works fine from Scala's REPL, but fails from within Scala compiler, with >> the following exception >> >> error: exception during macro expansion: >> java.lang.**IllegalStateExceptio**n: Attempting to call unbound fn: >> #'clojure.core/refer >> at clojure.lang.Var$Unbound.**throw**Arity(Var.java:43) >> at clojure.lang.AFn.invoke(AFn.**ja**va:39) >> at clojure.lang.Var.invoke(Var.**ja**va:415) >> at clojure.lang.RT.doInit(RT.**java**:449) >> at clojure.lang.RT.<clinit>(RT.**ja**va:318) >> at .foo_impl(<console>:8) >> >> Not only the classpath, but also the thread context ClassLoader is the >> same in both cases. >> >> I posted the details here: >> https://groups.google.com/**forum/?hl=en&fromgroups=#!** >> topic/scala-user/Bh_YmI6e-wY<https://groups.google.com/forum/?hl=en&fromgroups=#!topic/scala-user/Bh_YmI6e-wY> >> >> One could argue that this seems to be more of a Scala issue, but I did a >> search and it turns out that there are other similar situations where the >> Clojure runtime fails to initialize with the same error: >> >> - from within a Nutch plugin: >> https://groups.google.com/**forum/?hl=en&fromgroups=#!** >> searchin/clojure/nutch$**20plugin/clojure/Fbqrk1T8SRg/**CbQDd1yBvjYJ<https://groups.google.com/forum/?hl=en&fromgroups=#!searchin/clojure/nutch$20plugin/clojure/Fbqrk1T8SRg/CbQDd1yBvjYJ> >> >> - trying to deploy an EJB >> https://groups.google.com/**forum/?hl=en&fromgroups=#!** >> searchin/clojure/ejb/clojure/**FFe7Pf9TfXc/rxmYq6IoIjMJ<https://groups.google.com/forum/?hl=en&fromgroups=#!searchin/clojure/ejb/clojure/FFe7Pf9TfXc/rxmYq6IoIjMJ> >> >> - naming your project "clojure" in lein >> http://osdir.com/ml/java-**clojure-user/2012-04/msg00913.**html<http://osdir.com/ml/java-clojure-user/2012-04/msg00913.html> >> >> >> To further investigate my case, I tried to force the startup from >> core.clj rather than from the precompiled classes. >> Also in this case, the same call from the Scala repl works fine, whereas >> the call from within the Scala macro expansion fails, with this: >> >> ava.lang.ClassCastException: clojure.core$fn cannot be cast to >> clojure.lang.IFn, compiling:(clojure/core.clj:**55) >> at clojure.lang.Compiler.**analyzeSeq(Compiler.java:6462) >> at clojure.lang.Compiler.analyze(**Compiler.java:6262) >> at clojure.lang.Compiler.access$**100(Compiler.java:37) >> at clojure.lang.Compiler$DefExpr$**Parser.parse(Compiler.java:**518) >> at clojure.lang.Compiler.**analyzeSeq(Compiler.java:6455) >> at clojure.lang.Compiler.analyze(**Compiler.java:6262) >> at clojure.lang.Compiler.analyze(**Compiler.java:6223) >> at clojure.lang.Compiler.eval(**Compiler.java:6515) >> at clojure.lang.Compiler.load(**Compiler.java:6952) >> at clojure.lang.RT.**loadResourceScript(RT.java:**359) >> at clojure.lang.RT.**loadResourceScript(RT.java:**350) >> at clojure.lang.RT.load(RT.java:**429) >> at clojure.lang.RT.load(RT.java:**400) >> at clojure.lang.RT.doInit(RT.**java:436) >> at clojure.lang.RT.<clinit>(RT.**java:318) >> at .foo_impl(<console>:8) >> Caused by: java.lang.ClassCastException: clojure.core$fn cannot be cast >> to clojure.lang.IFn >> at clojure.lang.Var.fn(Var.java:**392) >> at clojure.lang.Var.invoke(Var.**java:431) >> at clojure.lang.AFn.**applyToHelper(AFn.java:178) >> at clojure.lang.Var.applyTo(Var.**java:532) >> at clojure.lang.Compiler.**macroexpand1(Compiler.java:**6366) >> at clojure.lang.Compiler.**analyzeSeq(Compiler.java:6441) >> at clojure.lang.Compiler.analyze(**Compiler.java:6262) >> at clojure.lang.Compiler.access$**100(Compiler.java:37) >> at clojure.lang.Compiler$DefExpr$**Parser.parse(Compiler.java:**518) >> at clojure.lang.Compiler.**analyzeSeq(Compiler.java:6455) >> at clojure.lang.Compiler.analyze(**Compiler.java:6262) >> at clojure.lang.Compiler.analyze(**Compiler.java:6223) >> at clojure.lang.Compiler.eval(**Compiler.java:6515) >> at clojure.lang.Compiler.load(**Compiler.java:6952) >> at clojure.lang.RT.**loadResourceScript(RT.java:**359) >> at clojure.lang.RT.**loadResourceScript(RT.java:**350) >> at clojure.lang.RT.load(RT.java:**429) >> at clojure.lang.RT.load(RT.java:**400) >> at clojure.lang.RT.doInit(RT.**java:436) >> at clojure.lang.RT.<clinit>(RT.**java:318) >> >> Thanks in advance for any help or pointer. >> >> Francesco >> > -- > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > > > -- I may be wrong or incomplete. Please express any corrections / additions, they are encouraged and appreciated. At least one entity is bound to be transformed if you do ;) -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en