Java: load shared libraries with dependencies

前端 未结 6 1835
别那么骄傲
别那么骄傲 2021-02-14 16:43

I am wrapping a shared library (written in C) with Java using JNA. The shared library is written internally, but that library uses functions from another external library, which

6条回答
  •  臣服心动
    2021-02-14 17:44

    Try this, add this function to your code. Call it before you load your dlls. For the parameter, use the location of your dlls.

    
        public boolean addDllLocationToPath(String dllLocation)
        {
            try
            {
                System.setProperty("java.library.path", System.getProperty("java.library.path") + ";" + dllLocation);
                Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
                fieldSysPath.setAccessible(true);
                fieldSysPath.set(null, null);
            }
            catch (Exception e)
            {
                System.err.println("Could not modify path");
                return false;
            }
            return true;
        }
    }
    
    

提交回复
热议问题