On Wed, Jun 13, 2012 at 11:48 PM, Warren Lynn <wrn.l...@gmail.com> wrote:
> Ok, I hit a wall and really did not see this coming.
>
> Based on what I have read, its really easy for Clojure and Java to
> work together. So I wrote some test Clojure code with a very simple
> defrecord (say named as "testrec") and AOT compile it, create a jar
> file, and add it to a "HelloWorld" java project in Eclipse. I can
> create object of class "testrec" and run its member functions. Cool,
> no problem.
>
> But then I put the same thing into my target Java system (for which I
> am consider Clojure for production use), I got
> "java.lang.ExceptionInInitializerError" exception when trying to
> create my "testrec" object. A little bit more digging suggests this is
> related to class loader, which I don't know much about. According to a
> web page, I need to do this:
>
> Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
>
> before calling the constructor of my "testrec" class. Tried that, but
> I got
>
> java.security.AccessControlException: access denied
> ("java.lang.RuntimePermission" "setContextClassLoader")
>
> Seems I cannot change the context class loader.
>
> What is the solution here?
>
> Sorry for the long post. But I hope this is not a dead end. Thanks a
> lot.

It's not really a good idea to AOT your code and then directly try to
use it from java. The generated java bytecode isn't guaranteed to be
stable across versions of clojure, and you're depending on
implementation details.

One way to use your clojure code from java is through RT. An example
would be the accepted answer here:
http://stackoverflow.com/questions/2181774/calling-clojure-from-java

Another tack you can take is to use gen-class to create a "real" java
class from clojure and use that as an entry point to your clojure
code.

--Aaron

-- 
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

Reply via email to