How to influence search path of System.loadLibrary() through Java code?

前端 未结 6 1213
一向
一向 2021-02-04 03:18

In a Java project, I am using a third-party library that loads some native library via

System.loadLibrary(\"libName\");

I\'d like to be able to

6条回答
  •  萌比男神i
    2021-02-04 03:56

    I needed to change the dll path for my unit tests. I tried the following hack and it worked:

    System.setProperty( "java.library.path", "/path/to/libs" ); 
    Field fieldSysPath = ClassLoader.class.getDeclaredField( "sys_paths" );
    fieldSysPath.setAccessible( true );
    fieldSysPath.set( null, null );
    

    For explanation, see the original link.

提交回复
热议问题