This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
The following commit(s) were added to refs/heads/main by this push:
new 9e15037e9 build(bindings/java): bundle bare binaries in JARs with
classifier (#2910)
9e15037e9 is described below
commit 9e15037e9630e4fd2eeb2c2f96af32db29a8119a
Author: tison <[email protected]>
AuthorDate: Wed Aug 23 18:44:20 2023 +0800
build(bindings/java): bundle bare binaries in JARs with classifier (#2910)
Signed-off-by: tison <[email protected]>
---
bindings/java/README.md | 18 ++++++++++++++++++
bindings/java/pom.xml | 4 +++-
.../src/main/java/org/apache/opendal/Environment.java | 19 ++++++++++++++++++-
.../main/java/org/apache/opendal/NativeObject.java | 6 +++---
bindings/java/src/main/resources/bindings.properties | 1 -
5 files changed, 42 insertions(+), 6 deletions(-)
diff --git a/bindings/java/README.md b/bindings/java/README.md
index 90b563613..3a2edacfe 100644
--- a/bindings/java/README.md
+++ b/bindings/java/README.md
@@ -26,6 +26,11 @@ Generally, you can first add the `os-maven-plugin` for
automatically detect the
Then add the dependency to `opendal-java` as following:
```xml
+<dependency>
+ <groupId>org.apache.opendal</groupId>
+ <artifactId>opendal-java</artifactId>
+ <version>${opendal.version}</version>
+</dependency>
<dependency>
<groupId>org.apache.opendal</groupId>
<artifactId>opendal-java</artifactId>
@@ -34,6 +39,19 @@ Then add the dependency to `opendal-java` as following:
</dependency>
```
+Note that the dependency without classifier ships all classes and resources
except the "opendal_java" shared library. And those with classifier bundle only
the shared library.
+
+For downstream usage, it's recommended:
+
+* Depend on the one without classifier to write code;
+* Depend on the classified ones with "test" for testing.
+
+To load the shared library correctly, you can choose one of the following
approaches:
+
+* Append the classified JARs to the classpath at the runtime;
+* Depend on the classified JARs and build a fat JAR (You may need to depend on
all the provided classified JARs for running on multiple platforms);
+* Build your own "opendal_java" shared library and specify
"-Djava.library.path" to the folder containing that shared library.
+
## Build
This project provides OpenDAL Java bindings with artifact name `opendal-java`.
It depends on JDK 8 or later.
diff --git a/bindings/java/pom.xml b/bindings/java/pom.xml
index a852ef648..b41b61bf3 100644
--- a/bindings/java/pom.xml
+++ b/bindings/java/pom.xml
@@ -186,7 +186,6 @@
<id>default-jar</id>
<configuration>
<excludes>
- <exclude>bindings.properties</exclude>
<exclude>native/**</exclude>
</excludes>
</configuration>
@@ -199,6 +198,9 @@
</goals>
<configuration>
<classifier>${jni.classifier}</classifier>
+ <includes>
+ <include>native/**</include>
+ </includes>
</configuration>
</execution>
</executions>
diff --git a/bindings/java/src/main/java/org/apache/opendal/Environment.java
b/bindings/java/src/main/java/org/apache/opendal/Environment.java
index 3ff87f0cc..ccdaab8ca 100644
--- a/bindings/java/src/main/java/org/apache/opendal/Environment.java
+++ b/bindings/java/src/main/java/org/apache/opendal/Environment.java
@@ -39,11 +39,28 @@ public enum Environment {
try (InputStream is =
classLoader.getResourceAsStream("bindings.properties")) {
final Properties properties = new Properties();
properties.load(is);
- INSTANCE.classifier = properties.getProperty("jni.classifier",
UNKNOWN);
INSTANCE.projectVersion =
properties.getProperty("project.version", UNKNOWN);
} catch (IOException e) {
throw new UncheckedIOException("cannot load environment properties
file", e);
}
+
+ final StringBuilder classifier = new StringBuilder();
+ final String os = System.getProperty("os.name").toLowerCase();
+ if (os.startsWith("windows")) {
+ classifier.append("windows");
+ } else if (os.startsWith("mac")) {
+ classifier.append("osx");
+ } else {
+ classifier.append("linux");
+ }
+ classifier.append("-");
+ final String arch = System.getProperty("os.arch").toLowerCase();
+ if (arch.equals("aarch64")) {
+ classifier.append("aarch_64");
+ } else {
+ classifier.append("x86_64");
+ }
+ INSTANCE.classifier = classifier.toString();
}
/**
diff --git a/bindings/java/src/main/java/org/apache/opendal/NativeObject.java
b/bindings/java/src/main/java/org/apache/opendal/NativeObject.java
index e4e593e22..d136e3659 100644
--- a/bindings/java/src/main/java/org/apache/opendal/NativeObject.java
+++ b/bindings/java/src/main/java/org/apache/opendal/NativeObject.java
@@ -81,7 +81,7 @@ public abstract class NativeObject implements AutoCloseable {
doLoadLibrary();
} catch (IOException e) {
libraryLoaded.set(LibraryState.NOT_LOADED);
- throw new UncheckedIOException("Unable to load the RocksDB
shared library", e);
+ throw new UncheckedIOException("Unable to load the OpenDAL
shared library", e);
}
libraryLoaded.set(LibraryState.LOADED);
return;
@@ -97,7 +97,7 @@ public abstract class NativeObject implements AutoCloseable {
private static void doLoadLibrary() throws IOException {
try {
- // try dynamic library
+ // try dynamic library - the search path can be configured via
"-Djava.library.path"
System.loadLibrary("opendal_java");
return;
} catch (UnsatisfiedLinkError ignore) {
@@ -111,7 +111,7 @@ public abstract class NativeObject implements AutoCloseable
{
final String libraryPath = bundledLibraryPath();
try (final InputStream is =
NativeObject.class.getResourceAsStream(libraryPath)) {
if (is == null) {
- throw new IOException("cannot find " + libraryPath + ", broken
package?");
+ throw new IOException("cannot find " + libraryPath);
}
final int dot = libraryPath.indexOf('.');
final File tmpFile = File.createTempFile(libraryPath.substring(0,
dot), libraryPath.substring(dot));
diff --git a/bindings/java/src/main/resources/bindings.properties
b/bindings/java/src/main/resources/bindings.properties
index b33089613..f2ef3fa7f 100644
--- a/bindings/java/src/main/resources/bindings.properties
+++ b/bindings/java/src/main/resources/bindings.properties
@@ -15,5 +15,4 @@
# specific language governing permissions and limitations
# under the License.
-jni.classifier=${jni.classifier}
project.version=${project.version}