Skip to content

Commit

Permalink
Merge pull request #19 from jerrydlamme/master
Browse files Browse the repository at this point in the history
Added architecture specific native library loading path
  • Loading branch information
chirino committed Apr 18, 2015
2 parents d10c4b0 + 1e2ee63 commit 86e97d1
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
* and and then loaded. This way you can embed your JNI libraries into your packaged JAR files.
* They are looked up as resources in this order:
* <ol>
* <li> "META-INF/native/${platform}/${arch}/${library}" : Store your library here if you want to embed
* more than one platform JNI library on different processor archs in the jar.
* <li> "META-INF/native/${platform}/${library}" : Store your library here if you want to embed more
* than one platform JNI library in the jar.
* <li> "META-INF/native/${library}": Store your library here if your JAR is only going to embedding one
Expand All @@ -55,6 +57,7 @@
* <li>"${os}" is your operating system, for example "osx", "linux", or "windows"</li>
* <li>"${bit-model}" is "64" if the JVM process is a 64 bit process, otherwise it's "32" if the
* JVM is a 32 bit process</li>
* <li>"${arch}" is the architecture for the processor, for example "amd64" or "sparcv9"</li>
* <li>"${platform}" is "${os}${bit-model}", for example "linux32" or "osx64" </li>
* <li>"${library}": is the normal jni library name for the platform. For example "${name}.dll" on
* windows, "lib${name}.jnilib" on OS X, and "lib${name}.so" on linux</li>
Expand Down Expand Up @@ -169,6 +172,8 @@ private void doLoad() {

/* Try extracting the library from the jar */
if( classLoader!=null ) {
if( exractAndLoad(errors, version, customPath, getArchSpecifcResourcePath()) )
return;
if( exractAndLoad(errors, version, customPath, getPlatformSpecifcResourcePath()) )
return;
if( exractAndLoad(errors, version, customPath, getOperatingSystemSpecifcResourcePath()) )
Expand All @@ -182,6 +187,10 @@ private void doLoad() {
throw new UnsatisfiedLinkError("Could not load library. Reasons: " + errors.toString());
}

final public String getArchSpecifcResourcePath() {
return "META-INF/native/"+ getPlatform() + "/" + System.getProperty("os.arch") + "/" +map(name);
}

final public String getOperatingSystemSpecifcResourcePath() {
return getPlatformSpecifcResourcePath(getOperatingSystem());
}
Expand Down

0 comments on commit 86e97d1

Please sign in to comment.