Debian Codegraph @

tools/jni/org/jpeg/jpegli/wrapper/JniHelper.java

raw
1 // Copyright (c) the JPEG XL Project Authors. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file.
5
6 package org.jpeg.jpegli.wrapper;
7
8 import java.io.File;
9
10 /**
11 * Helper for native library loading.
12 *
13 * Normally the wrapper is responsible for (lazy) library loading; though it is
14 * sometimes necessary to make the moment of loading more deterministic.
15 */
16 public class JniHelper {
17 /** Utility library, disable object construction. */
18 private JniHelper() {}
19
20 static {
21 String jniLibrary = System.getProperty("org.jpeg.jpegli.wrapper.lib");
22 if (jniLibrary != null) {
23 try {
24 System.load(new File(jniLibrary).getAbsolutePath());
25 } catch (UnsatisfiedLinkError ex) {
26 String message = "If the nested exception message says that some standard library (stdc++, "
27 + "tcmalloc, etc.) was not found, it is likely that JDK discovered by the "
28 + "build system overrides library search path. Try specifying a different "
29 + "JDK via JAVA_HOME environment variable and doing a clean build.";
30 throw new IllegalStateException(message, ex);
31 }
32 }
33 }
34
35 static void ensureInitialized() {
36 // Do nothing, just trigger static initializer.
37 }
38 }