JavaCPP and java.library.path

743 views
Skip to first unread message

Bob Ziuchkovski

unread,
Oct 8, 2012, 9:12:47 PM10/8/12
to javacpp...@googlegroups.com
Hi,

I've been happily using JavaCPP for project I'm working on. However, up
to this point I have been using workarounds for the JNI library loading.
Now I'm working on packaging and it is time to figure out where I'm
going wrong. :)

Here's what I have in a very simplified overview:

core.so -- C++ core library
core-java.jar -- contains the JavaCPP code that bridges to core.so
frontend.jar -- GUI app that consumes the bindings from core-java.jar

If I try to launch frontend.jar with core-java.jar and frontend.jar in
the classpath, I end up with a link error such as

java.lang.UnsatisfiedLinkError: no jniCore in java.library.path

jniCore.so does exist in core-java.jar/lib. While doing development, I
have generally just extracted jniCore.so and added it to
java.library.path while launching the app.

However, now that I'm working on packaging for the application, it's
time for me to figure out a better solution.

Does JavaCPP support loading the JNI libs from the JAR classpath? I
thought it did, but perhaps I'm wrong. Or perhaps it is getting
confused by the fact that frontend.jar is the jar consuming
core-java.jar, which contains the JNI lib and JavaCPP code?

Let me know what you guys think. Thanks!

Bob

Samuel Audet

unread,
Oct 8, 2012, 10:41:48 PM10/8/12
to javacpp...@googlegroups.com
Hello,

You can use whatever method you want to load your libraries, including
using Loader.extractResource(), and calling System.load() on the
extracted file and what not, but for different platforms we need to
manage different binaries, which also have different prefixes and
suffixes appended to the library name...

If you want to use JavaCPP to take care of that for you, you can either
not use "-d" and "-o", leaving the Builder put the files in the right
packages, or you can include the libraries in the package namespace of
some class + "/" + platform.name and call `Loader.loadLibrary(libname)`
from inside that class. That makes sense?

Samuel

Bob Ziuchkovski

unread,
Oct 13, 2012, 12:59:57 PM10/13/12
to javacpp...@googlegroups.com
Hi Samuel,

I wasn't aware of System.load(). I went with that approach and all is
working well. Thanks for the info!

Bob

angst...@gmail.com

unread,
May 6, 2016, 7:10:40 PM5/6/16
to javacpp
Hi,

Could you be a little bit more specific. How can we pack our .so file inside of jar and still be able to reference it? Thanks!

Samuel Audet

unread,
May 6, 2016, 9:24:44 PM5/6/16
to javacpp...@googlegroups.com
Well, for example, try this sample:
https://github.com/bytedeco/javacpp#accessing-native-apis

Now, instead of just running "java -cp javacpp.jar NativeLibrary", try
to do something like "jar cvf NativeLibrary.jar *" and "java -cp
javacpp.jar:NativeLibrary.jar NativeLibrary". It still works after
removing the original files outside of the archive.

Samuel
Reply all
Reply to author
Forward
0 new messages