GithubHelp home page GithubHelp logo

Comments (10)

mkristian avatar mkristian commented on August 18, 2024 1

will have look into this first thing next year :)

from jnr-ffi.

btiernay avatar btiernay commented on August 18, 2024

I was able to work around this issue by doing the following:

    ClosureManager closureManager = NativeRuntime.getInstance().getClosureManager();
    val classLoader = findField(closureManager.getClass(), "classLoader");
    classLoader.setAccessible(true);
    val asmClassLoader = classLoader.get(closureManager);

    val parent = findField(asmClassLoader.getClass(), "parent");
    parent.setAccessible(true);
    parent.set(asmClassLoader, Thread.currentThread().getContextClassLoader());

from jnr-ffi.

mkristian avatar mkristian commented on August 18, 2024

this means when we switch to the context classloader that in OSGi case it can not find its classes since OSGi does not work with context classloader at all.

but probably you are right in the respect that ClassLoader.getSystemClassLoader() is not the right thing. I would say that getClass().getClassLoader() is the better choice which will work when everything is loaded from the context classloader and with the OSGi case as well.

from jnr-ffi.

btiernay avatar btiernay commented on August 18, 2024

That would be a better default. Also, would it be possible to make this configurable maybe?

from jnr-ffi.

headius avatar headius commented on August 18, 2024

See contributed test case in #55.

from jnr-ffi.

neupsh avatar neupsh commented on August 18, 2024

Is there any update on this issue? I was trying to use jnr related java library in clojure and when i run the project with boot-clj build tool, it fails to load the class with:

java.lang.ClassNotFoundException: jnr.ffi.provider.jffi.NativeClosureProxy
             java.lang.NoClassDefFoundError: jnr/ffi/provider/jffi/NativeClosureProxy
                 java.lang.RuntimeException: java.lang.NoClassDefFoundError: jnr/ffi/provider/jffi/NativeClosureProxy

This is because, boot-clj runs 'boot-tasks' in 'pods', which are clojure runtimes in single JVM. They are separated by different classloaders and thus the dependencies are tied to these different classloaders. The System ClassLoader does not have any libraries in the classpath and as a result, it fails to load the class.

from jnr-ffi.

headius avatar headius commented on August 18, 2024

Let's try fixing this with getClass().getClassLoader() falling back on ClassLoader.getSystemClassLoader() when that is null. I'll commit that and y'all can test it.

from jnr-ffi.

headius avatar headius commented on August 18, 2024

I've pushed a fix and will release 2.1.3 shortly.

from jnr-ffi.

gzunino avatar gzunino commented on August 18, 2024

This is not enough for OSGi running jnr as bundle, when a closure defines a return type with a Class defined in another bundle. For example:

BundleA > BundleJNR (BundleA depends on BundleJNR)

a callback on BundleA with a return type ClassA, being ClassA a class on BundleA.

JNR tries to load ClassA with the classloader of BundleJNR and fails to do it.

from jnr-ffi.

realPyR3X avatar realPyR3X commented on August 18, 2024

Has this issue been resolved for OSGi? I'm trying to use JavaFS which relies on this library and I continue to get The activate method has thrown an exception

The activate method has thrown an exception java.lang.RuntimeException: java.lang.NoClassDefFoundError: jnr/ffi/provider/jffi/AsmStructByReferenceFromNativeConverter

from jnr-ffi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.