Difference between System.load() and System.loadLibrary in Java
Asked Answered
T

1

79

What is the difference between System.load() and System.loadLibrary() in java?

I want to load a library but I don't want to add the path to environment variables. Will any one of these help?

Troxler answered 10/8, 2011 at 19:11 Comment(0)
L
97

The difference is there in the API documentation. System.loadLibrary(String libname) lets you load from the default path -- The Java library path.

The other System.load(String filename) lets you load it from an absolute path, which you must specify as your filename.

If you don't want to mess with you java.library.path environment variable, you should use System.load()

Lothians answered 10/8, 2011 at 19:20 Comment(2)
Right now I am haing a library which I am loading using system.load("path to library"); And I am adding this path in the system environmebt variables. If I dont add then I am getting unsatisfied link error. Is there any way I can skip this adding this library path in system environment variable.Troxler
The drawback of loadLibrary() is so that it returns the confusing error message "java.lang.UnsatisfiedLinkError: myLib (Not found in java.library.path)" even if it is found, but could not be loaded due to other reasons. In such case calling load()/loadLibrary() with the absolute path shows additional output like "rtld: Symbol myFunc was referenced ... but a runtime definition was not found." which is hidden by loadLibrary() with the library basename as argument. That is the best way is to write own method which iterates through java.library.path and calls load() per item.Hermineherminia

© 2022 - 2024 — McMap. All rights reserved.