简体   繁体   中英

When I run the following code, it throws an Exception, why?

code:

public class JniTest {
    static {    
       System.load("/usr/lib/libJniTest.so"); //It run have no exception and true
               //System.loadLibrary("libJniTest");
    }
    public native void sayHello();

    public static void main(String[] args) {

    System.out.println(System.getProperties().getProperty("java.library.path"));
    new JniTest().sayHello();
    }
}

If use the comments code instead of "System.load("/usr/lib/libJniTest.so") , it will throw exception:

 Exception in thread "main" java.lang.UnsatisfiedLinkError: no libJniTest in   java.library.path!

I have input

export LD_LIBRARY_PATH=/usr/lib in /etc/profile and set vm arguments:
-Djava.library.path=/usr/lib

Help me, Please!

Set VM arguments with :

-Djava.library.path="${workspace_loc}/project_name:${env_var:PATH}"

and make sure that .so should be in your project folder

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM