Workshop proposal: loading native code from modules

Johan Vos johan.vos at gluonhq.com
Sat Jul 14 10:12:21 UTC 2018


The Java SDK has always been distributed as an SDK that resides on a host
filesystem and it contains a directory and a number of subdirectories.
Inside those directories, platform-specific native libraries are located,
e.g. containing the implementations for native functions.

This model works fine for the core Java SDK with the core classes, as it
can be assumed the user will download and install the SDK including the
platform-specific native libraries.

However, there is an increasing amount of downloadable software that may
also contain platform-specific native implementations of some code:
* more software is created that leverages platform
(OS/arch/.../CPU/GPU/...) specific functionalities
* components that are removed from the core Java SDK that contain native
code (e.g. OpenJFX)
* code that is (partially) be compiled using an AOT.

Unless those projects all provide SDK's that are happily downloaded by the
end user, one can not rely on the fact that the native libraries are 1) on
the device file system and 2) on the LD_LIBRARY_PATH.
In order to fix this, a number of projects use different approaches to deal
with loading native code that is provided (typically as a resource) inside
a jar file.

In OpenJFX, we are adding some functionality to the NativeLibLoader (
https://github.com/johanvos/openjdk-jfx/blob/nativelibs/modules/javafx.graphics/src/main/java/com/sun/glass/utils/NativeLibLoader.java#L192
)
There is a project at github that deals with this more general:
https://github.com/bytedeco/javacpp

Given the fact that there are more and more use cases for this scenario
(where native code is not on the filesystem, but inside a jar or a module),
I think it would be beneficial to think about best practices, and hopefully
a standard approach.


More information about the workshop-discuss mailing list