"Jim - FooBar();" <[email protected]> writes:

> Now, the first time I (load-file "xxx.core.clj") everything is
> perfectly fine. The minute I make a change and re-load I get:
>
> NoClassDefFoundError Could not initialize class yyy.Foo

This confuses me, because the JVM should only be loading and
initializing the Java class once.  Re-loading the Clojure namespace
shouldn’t report an error unless initialization actually failed the
first time around.

That said, you will definitely get errors if you have a Java class
`require` a namespace in a static initializer which then `import`s the
class.  Clojure `import` causes referenced classes to be initialized,
which runs static initializers, which means a circular namespace ->
initializer -> namespace dependency effectively reduces to a circular
namespace dependency.

The solution I’ve been using lately is to push the Java-side
namespace-loading into a private static inner class of the original Java
class.  This provides the benefits of JVM-managed single-initialization,
but defers execution of that initialization code until something
actually needs one of the imported Vars.  Example:

    
https://github.com/damballa/abracad/blob/master/src/java/abracad/avro/ClojureDatumReader.java

HTH,

-Marshall

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to