Setting different class loader

Mark Evenson evenson at panix.com
Mon Feb 6 09:09:48 UTC 2023



> On Jul 23, 2020, at 08:37, Steven Nunez <steve_nunez at yahoo.com> wrote:
> 
> Thank you Olof; that was just what I needed to get things working. Well, that and another half day struggling with what turns out to be a 5 year old bug (#388). I really wish someone had mentioned in the JSS documentation, "Oh, and this doesn't yet work in top-level forms". All told, it was a lot more difficult to get started with ABCL than I expected it to be, but I'm glad it's done and grateful to those that helped. For reference, here's the code that finally works:
> 
> (defun change-class-loader ()
>   (#"setContextClassLoader" #1"Thread.currentThread()" (java:get-current-classloader)))
> (change-class-loader)
> 
> 
> At least it gets me as far as line two of the spark 'hello world'; hopefully there aren't any other surprises lurking. If anyone can recommend any best practices or improvements, especially around the class loader bits, I'd be very happy to hear them.

[…]
> 
> Hopefully there's a better way of course, since this is hardly
> convenient.

Slightly more convenient perhaps is to change the context ClassLoader
in the ASDF :PERFORM clause
<https://github.com/easye/ember/blob/master/ember.asd#L7> before
the Spark Maven artifacts are loaded:

    (defsystem ember
      :description "Wrapper for Spark 3.0"
      :defsystem-depends-on (jss abcl-asdf)
      :depends-on (#:jss #:javaparser)
      :perform (load-op (o c)
                        (#"setContextClassLoader" (#"currentThread" 'Thread)
                                                  (java:get-current-classloader))
                        (call-next-method o c))
      :components ((:mvn "org.apache.spark/spark-core_2.12" :version "3.0.0")
                   (:file "package")
                   (:file "ember")))

Such a setting of the context ClassLoader seems to be quite useful
for integrating quite a few Java libraries with ABCL, I wonder if
it shouldn't be the default for ABCL-ASDF loading Maven artifacts
to set the context ClassLoader is this manner.  Would such a choice
adversely affect anyones current usage?  I almost exclusively use
ABCL via SLIME, so maybe production use of ABCL (i.e. as a standalone
packaged application) would run into problems here.  Thoughts?

For those using, openjdk17 one needs to set the [following run-time
switch in the JVM][1]:

  —add-opens java.base/sun.nio.ch=ALL-UNNAMED 

As a bonus, that annoying [seven (!) year old bug][338], has been
recently been fixed by Alejandro Zamora Fonseca for the [upcoming
abcl-1.9.1 release][1.9.1].
 

[1]: <https://stackoverflow.com/questions/72230174/java-17-solution-for-spark-java-lang-noclassdeffounderror-could-not-initializ>
[338]: <https://abcl.org/trac/ticket/338> 
[1.9.1]: <https://github.com/armedbear/abcl/pull/534>

-- 
"A screaming comes across the sky.  It has happened before but there is nothing 
to compare to it now."








More information about the armedbear-devel mailing list