Set library path for embedded

39 views
Skip to first unread message

Roberto Vieweg

unread,
Dec 15, 2020, 6:31:15 AM12/15/20
to firebird-java
I'm starting a new project to embed all firebird platform distributions in a single jar.

The jar will extract the files (dlls, etc) to a temporary directory.

To do this, I need to know if there are a way to set to jaybird driver the "path" to load the firebird libraries.

If not, I'll need to change the "java.library.path" at runtime and this is not a good practice.

Mark Rotteveel

unread,
Dec 15, 2020, 11:20:08 AM12/15/20
to firebi...@googlegroups.com
On 2020-12-15 12:31, Roberto Vieweg wrote:
> I'm starting a new project to embed all firebird platform
> distributions in a single jar.

Jaybird 5 will introduce a plugin mechanism to provide just that, and
the plan is to provide jars to distribute Firebird Embedded. It would be
unfortunate if we are duplicating effort here. Maybe we should see if we
can work together on this in some way to avoid reinventing the wheel and
duplicating work.

See
https://github.com/FirebirdSQL/jaybird/blob/master/devdoc/jdp/jdp-2020-05-firebird-embedded-locator-service-provider.md
for details, and
https://github.com/FirebirdSQL/jaybird/tree/master/src/jna-client/org/firebirdsql/jna/embedded
and sub-packages.

> The jar will extract the files (dlls, etc) to a temporary directory.

Jaybird 5 will provide classes to do this for you (see
https://github.com/FirebirdSQL/jaybird/blob/master/src/jna-client/org/firebirdsql/jna/embedded/classpath/ClasspathFirebirdEmbeddedLoader.java),
though the plugin mechanism doesn't require you to use this.

> To do this, I need to know if there are a way to set to jaybird driver
> the "path" to load the firebird libraries.
>
> If not, I'll need to change the "java.library.path" at runtime and
> this is not a good practice.

Since Jaybird 3, Jaybird uses JNA, which uses jna.library.path, not
java.library.path, and the context classloader (see
http://java-native-access.github.io/jna/5.6.0/javadoc/com/sun/jna/NativeLibrary.html#library_search_paths),
but it also has additional features to load a library using a full path
to the library, which is what this plugin mechanism will use, and
methods to extend the search path.

For example, you can use com.sun.jna.NativeLibrary.addSearchPath(String
libraryName, String path) to add a path (a directory) for a specific
library name. For embedded, Jaybird tries the library names "fbembed"
(Firebird 2.5 and earlier) and "fbclient" (Firebird 3 and higher, or
renamed to fbclient.dll, etc). So
NativeLibrary.addSearchPath("fbclient", "C:/Temp/firebird") will make
JNA search in that location.

Be aware, this is not definitive yet, and things might change when I get
around to building and testing this on Linux and macOS. I have it
working for Windows right now, but I still need to work out how to
create a deployment (manually committing the necessary files to a
repository like I do for the org.firebirdsql.jdbc:fbclient library seems
a bit inefficient).

Mark
Reply all
Reply to author
Forward
0 new messages