Closed bjmi closed 3 years ago
Can you double check the latest commit. I think it should fix the issue. Here is the generated manifest (though not including all platforms):
Manifest-Version: 1.0
Automatic-Module-Name: com.github.luben.zstd_jni
Bnd-LastModified: 1597920893823
Bundle-Description: JNI bindings for Zstd native library that provides
fast and high compression lossless algorithm for Java and all JVM la
nguages.
Bundle-License: https://opensource.org/licenses/BSD-2-Clause;descripti
on=BSD 2-Clause License
Bundle-ManifestVersion: 2
Bundle-Name: zstd-jni
Bundle-SymbolicName: com.github.luben.zstd-jni
Bundle-Vendor: com.github.luben
Bundle-Version: 1.4.5.7
Created-By: 1.8.0_265 (Private Build)
Eclipse-BundleShape: dir
Export-Package: com.github.luben.zstd;version="1.4.5.7",com.github.lub
en.zstd.util;version="1.4.5.7"
Implementation-Title: zstd-jni
Implementation-Vendor: com.github.luben
Implementation-Vendor-Id: com.github.luben
Implementation-Version: 1.4.5-7
Import-Package: com.github.luben.zstd.util
Private-Package: include,linux.amd64
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"
Specification-Title: zstd-jni
Specification-Vendor: com.github.luben
Specification-Version: 1.4.5-7
Tool: Bnd-4.0.0.201805111645
Does it look right? I don't have much experience with OSGI bundles TBH.
It looks right but now I noticed that a copy of the library is still copied to the temp folder and is loaded there although the complete bundle lies extracted in the filesystem.
I.e. there is no use declaring Eclipse-BundleShape: dir
. Exporting com.github.luben.zstd.util suffices. I apologize for the inconvenience.
My workaround in an eclipse application would be then
Native.resourceName()
reflectivlyorg.eclipse.core.runtime.FileLocator.toFileURL(URL)
) and determine absolute pathjava.lang.System.load(String)
by myselfNative.loaded
to true reflectivlyYes, I will remove the BundleShape.
BTW, can you explain a little bit of context and what you try to achieve?
On Windows another copy of libzstd-jni.dll resides in temp folder after every JVM execution and fills up this folder. Every run of an application that uses zstd-jni leaves files like libzstd-jni12927920263990567387.dll there.
If the library is accessible in filesystem the class Native
could try System.load(String)
directly without creating a copy in temp folder.
Direct loading proposal: try this at first in Native.load(File)
.
URL url = Native.class.getResource(resourceName);
if ("file".equals(url.getProtocol())) {
System.load(new File(url.toURI()).getAbsolutePath());
}
then Eclipse-BundleShape: dir
fits perfectly.
Yes, I can try this though I will need your help for verifying that it has the right behavior as I don't have Windows at hand.
It is more difficult than expected.
Running in Eclipse Class.getResource(resourceName)
returns an URL with bundleresource protocol e.g. bundleresource://9.fwk453059702:1/win/amd64/libzstd-jni.dll
even if the bundle lies extracted in file system. Therefore checking for file protocol doesn't work in this case. I'll open a new issue if I find a solution for that.
Returning to initial request: just export com.github.luben.zstd.util package. Thanks in advance.
addressed and released in v1.4.5-7
Calling
Native.load(File)
as described in this comment is not possible because package com.github.luben.zstd.util is not exported in MANIFEST.MF.The error is described as following:
Additionally please consider adding this header in MANFEST.MF.
Eclipse-BundleShape: dir
This allows loading libraries directly because the bundle is already extracted in filesystem. Reference: https://help.eclipse.org/2020-06/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fmisc%2Fbundle_manifest.html