How to load a library .so /.dll at startup

hy yall,

sorry for this basic question that is not link to JME, but i didn’t found any interresting result via google, and i know that this behavior is done by JME, cause we don’t need any LD_LIBRARY_PATH to set before startup.

so what’s the ggod way to do it ?


to be more accurate on my need, the library will idealy be in a jar file

i’m going to try something based on that :

[java]public static void loadNativeLibrary() throws Exception {

if( LIB_LOADED == false ) {

String libname = System.getProperty(“”)

  • “_”
  • System.getProperty(“os.arch”)
  • “.lib”;

    ClassLoader cl = Class.forName(“”)


    InputStream in = cl.getResourceAsStream(libname);

    if (in == null) {

    throw new Exception("libname: "
  • libname

    +" not found (supposed to be in sqliteimporter.jar)");


  • Extract the lib file and link it with the app


    File tmplib = File.createTempFile(“libsqlitejdbc-”, “.lib”);


    OutputStream out = new FileOutputStream(tmplib);

    byte[] buf = new byte[1024];

    for (int len; (len = != -1;) {

    out.write(buf, 0, len);





    LIB_LOADED = Boolean.TRUE;



    found on a french website :

    Is that a good way ? is that who you guys do for lwjgl ?

I think what you do is just extracting the lib from the jar and copying at the root of the project, to do not have to use System.load…

arff, i really have a bad time with that