diff --git a/pom.xml b/pom.xml index 184d92d..3aec72e 100644 --- a/pom.xml +++ b/pom.xml @@ -9,8 +9,8 @@ UTF-8 - 11 - 11 + 8 + 8 false Debug @@ -33,7 +33,7 @@ com.googlecode.cmake-maven-project cmake-maven-plugin - 3.23.2-b1 + 3.27.7-b1 cmake-generate @@ -181,4 +181,16 @@ + + + junpzx-custom-nexus + junpzx-custom-nexus-snapshots + https://repository.junpzx.cn/repository/maven-local-snapshot/ + + + junpzx-custom-nexus + junpzx-custom-nexus-releases + https://repository.junpzx.cn/repository/maven-local/ + + \ No newline at end of file diff --git a/src/main/java/org/gmssl/NativeLoader.java b/src/main/java/org/gmssl/NativeLoader.java index dc119b8..0e28827 100644 --- a/src/main/java/org/gmssl/NativeLoader.java +++ b/src/main/java/org/gmssl/NativeLoader.java @@ -8,7 +8,9 @@ */ package org.gmssl; -import java.io.*; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; @@ -17,17 +19,15 @@ /** * @author yongfei.li - * @email 290836576@qq.com + * @email 290836576@qq.com * @date 2023/09/07 * @description Native lib load util */ public class NativeLoader { + static final String GMSSLJNILIB_NAME = "libgmssljni"; /* custom jni library prefix path relative to project resources */ private static final String RESOURCELIB_PREFIXPATH = "lib"; - - static final String GMSSLJNILIB_NAME="libgmssljni"; - private static final Properties PROPERTIES = new Properties(); static { @@ -44,64 +44,66 @@ public class NativeLoader { /** * load jni lib from resources path,the parameter does not contain the path and suffix. - * @param libaray libarayName * + * @param libaray libarayName */ - public synchronized static void load (String libaray){ + public synchronized static void load(String libaray) { String resourceLibPath = RESOURCELIB_PREFIXPATH + "/" + libaray + "." + libExtension(); try (InputStream inputStream = NativeLoader.class.getClassLoader().getResourceAsStream(resourceLibPath)) { if (null == inputStream) { throw new GmSSLException("lib file not found in JAR: " + resourceLibPath); } - Path tempFile = Files.createTempFile(libaray, "."+libExtension()); + Path tempFile = Files.createTempFile(libaray, "." + libExtension()); tempFile.toFile().deleteOnExit(); Files.copy(inputStream, tempFile, StandardCopyOption.REPLACE_EXISTING); checkReferencedLib(); System.load(tempFile.toAbsolutePath().toString()); } catch (Exception e) { - throw new GmSSLException("Unable to load lib from JAR"); + throw new GmSSLException("Unable to load lib from JAR,resourceLibPath:" + resourceLibPath); } } /** * Get the operating system type. + * * @return operating system name */ - static String osType(){ - String os="unknown"; + static String osType() { + String os = "unknown"; String osName = System.getProperty("os.name").toLowerCase(); - if(osName.startsWith("windows")){ - os="win"; + if (osName.startsWith("windows")) { + os = "win"; } - if(osName.startsWith("linux")){ + if (osName.startsWith("linux")) { if ("dalvik".equalsIgnoreCase(System.getProperty("java.vm.name"))) { os = "android"; System.setProperty("jna.nounpack", "true"); } else { - os="linux"; + os = "linux"; } } - if(osName.startsWith("mac os x") || osName.startsWith("darwin")){ - os="osx"; + if (osName.startsWith("mac os x") || osName.startsWith("darwin")) { + os = "osx"; } return os; } /** * Get the library extension name based on the operating system type. + * * @return extension name */ - static String libExtension(){ - String osType=osType(); - String libExtension=null; - if("win".equals(osType)){ - libExtension="dll"; + static String libExtension() { + String osType = osType(); + String libExtension = null; + if ("win".equals(osType)) { + libExtension = "dll"; } - if("osx".equals(osType)){ - libExtension="dylib"; + if ("osx".equals(osType)) { + libExtension = "dylib"; } - if("linux".equals(osType)){ - libExtension="so"; + if ("linux".equals(osType)) { + libExtension = "so"; } return libExtension; } @@ -112,20 +114,19 @@ static String libExtension(){ * in order to correct the @rpath path issue. Alternatively, you can manually execute the command * "install_name_tool -change @rpath/libgmssl.3.dylib /usr/local/lib/libgmssl.3.dylib xxx/lib/libgmssljni.dylib" to fix the library reference path issue. * This has already been loaded and manual execution is unnecessary. - * */ - private static void checkReferencedLib(){ - if("osx".equals(osType())){ - String macReferencedLib=PROPERTIES.getProperty("macReferencedLib"); - Optional optionalStr = Optional.ofNullable(macReferencedLib); - if(optionalStr.isPresent() && !optionalStr.get().isEmpty()){ - File libFile = new File(macReferencedLib); - if(libFile.exists()){ - System.load(macReferencedLib); - } - } + private static void checkReferencedLib() { + if ("osx".equals(osType())) { + String macReferencedLib = PROPERTIES.getProperty("macReferencedLib"); + Optional optionalStr = Optional.ofNullable(macReferencedLib); + if (optionalStr.isPresent() && !optionalStr.get().isEmpty()) { + File libFile = new File(macReferencedLib); + if (libFile.exists()) { + System.load(macReferencedLib); + } + } - } - } + } + } }