(LoadError) Could not load FFI Provider - when using jruby-core jars (1.7.4)

Hi,

I am getting this exception with FFI when using jruby-core jars but NOT
when using jruby-complete.jar:

org.jruby.exceptions.RaiseException: (LoadError) Could not load FFI
Provider: (NotImplementedError) FFI not available: Could not initialize
class com.kenai.jffi.Foreign$InstanceHolder
See http://jira.codehaus.org/browse/JRUBY-4583

It seems that the libffi libraries are not included in any of the
jruby-core jars. The following is included in jruby-complete.jar but NOT
in
any of the jruby-core jars:

jni/x86_64-FreeBSD/
jni/x86_64-FreeBSD/libjffi-1.2.so
jni/x86_64-Linux/
jni/x86_64-Linux/libjffi-1.2.so
jni/x86_64-SunOS/
jni/x86_64-SunOS/libjffi-1.2.so
jni/x86_64-Windows/
jni/x86_64-Windows/jffi-1.2.dll

I am trying to figure how I could include these into my dependencies
alongside the jruby-core jars. Any ideas?

Thanks,
Colin

It depends on what dependency management you’re using.

If maven-ish (or anything that can use a maven repo, such as gradle,
ivy, etc), then add a dependency on com.github.jnr:jffi, something
like:

com.github.jnr jffi 1.2.7

Or, just download and add
https://oss.sonatype.org/content/repositories/releases/com/github/jnr/jffi/1.2.7/jffi-1.2.7-native.jar
to your classpath.

Wayne,

I am using the jruby-core 1.7.4 artifact as a dependency which depends
on
jffi 1.2.5 so jffi-1.2.5.jar is downloaded but not
jffi-1.2.5-native.jar.

I am using Ivy and currently stuck at trying to include
jffi-1.2.5-native.jar as an extra dependency.

Colin

Ahh, thats a fairly easy fix - since the binaries are packaged
separately to the main pom, you need an explicit dependency on the
native assembly.

com.github.jnr jffi 1.2.7 runtime native

Why that isn’t in jruby-core itself, or at least getting pulled in via
the jruby-core -> jnr-ffi dependency chain, I’m not too sure.

the jruby-core artifact should pull in exactly the same jars as
jruby-complete artifact.

looking at
$mvn dependency:tree
demo:demo:jar:demo
[INFO] - org.jruby:jruby-core:jar:1.7.4:compile
[INFO] ± org.jruby:jruby-stdlib:jar:1.7.4:compile
[INFO] ± org.jruby.joni:joni:jar:2.0.0:compile
[INFO] ± com.github.jnr:jnr-netdb:jar:1.1.2:compile
[INFO] ± com.github.jnr:jnr-enxio:jar:0.4:compile
[INFO] ± com.github.jnr:jnr-unixsocket:jar:0.3:compile
[INFO] ± com.github.jnr:jnr-posix:jar:2.5.2:compile
[INFO] ± org.jruby.extras:bytelist:jar:1.0.10:compile
[INFO] ± com.github.jnr:jnr-constants:jar:0.8.4:compile
[INFO] ± org.jruby.jcodings:jcodings:jar:1.0.10:compile
[INFO] ± com.github.jnr:jffi:jar:1.2.5:compile
[INFO] ± org.yaml:snakeyaml:jar:1.11:compile
[INFO] ± jline:jline:jar:2.7:compile
[INFO] ± joda-time:joda-time:jar:2.1:compile
[INFO] ± com.jcraft:jzlib:jar:1.1.2:compile
[INFO] ± com.headius:invokebinder:jar:1.2:compile
[INFO] - com.github.jnr:jnr-ffi:jar:1.0.4:compile
[INFO] ± com.github.jnr:jffi:jar:native:1.2.7:runtime
[INFO] - com.github.jnr:jnr-x86asm:jar:1.0.2:compile

with a pom with only jruby-core as depdenceny. this shows that
com.github.jnr:jffi:jar:native:1.2.7:runtime is pulled in by the
dependency
manager.

so I am still sure that jruby-core+transitive dependencies is
essentially
the same as jruby-complete. could it be that there is loading issue of
the
native lib - just guessing ?

  • christian

ah-ah! classifier! thanks, I got it to include the native dependency and
for the record here’s my Ivy config:

and “classifier” is needed in the retrieve pattern, with something like:

ant.retrieve “pattern” =>
“[conf]/artifact-[revision].[ext]”

Thanks,
Colin

Hi I think that core jar dont include things thats not core … For a
jar
with dependeces its better to use complete jar and then include
additional
jars at classpath. I think that this includes could be posible even with
core but things will be more difficult… Because you must do again work
thats someone did to bundle complete jar container.

Regards
El 20/06/2013 20:03, “Colin Surprenant” [email protected]
escribi:

I am not very good with both Ivy & Maven so this might just be caused by
my
weakness with these tools… A basic transitive dependency on jruby-core
with Ivy like this:

does not include jffi-native.

so looking at your dependency tree, jffi-native is in the maven
“runtime”
scope. I have tried without success to specify a runtime conf in Ivy to
include jffi-native. Again this might just be me not doing it right.

Manuel: jruby-complete can be useful but is not a good option when you
are
also dealing with other dependencies - with jruby-complete, it is not
possible to resolve conflicting jars etc.

Colin

it might very well be a Ivy thingy :wink: great that you found a solution.

maybe it is worth to declare com.github.jnr:jffi:jar:native:1.2.7 with
scope compile to keep the usage of jruby-core simple for Ivy users :slight_smile:

-christian

On Fri, Jun 21, 2013 at 7:34 PM, Colin Surprenant <