Java: carrega uma biblioteca que depende de outras bibliotecas

Eu quero carregar minhas próprias bibliotecas nativas no meu aplicativo java. Essas bibliotecas nativas dependem de bibliotecas de terceiros (que podem ou não estar presentes quando meu aplicativo é instalado no computador cliente

Dentro do meu aplicativo java, peço ao usuário que especifique o local das bibliotecas dependentes. Depois de obter essas informações, estou usando-as para atualizar a variável de ambiente "LD_LIBRARY_PATH" usando o código JNI. A seguir, está o trecho de código que estou usando para alterar a variável de ambiente "LD_LIBRARY_PATH".

Java code

public static final int setEnv(String key, String value) {
        if (key == null) {
            throw new NullPointerException("key cannot be null");
        }
        if (value == null) {
            throw new NullPointerException("value cannot be null");
        }
        return nativeSetEnv(key, value);
    }

public static final native int nativeSetEnv(String key, String value);

Jni código (C)

    JNIEXPORT jint JNICALL Java_Test_nativeSetEnv(JNIEnv *env, jclass cls, jstring key, jstring value) {
    const char *nativeKey = NULL;
    const char *nativeValue = NULL;
    nativeKey = (*env)->GetStringUTFChars(env, key, NULL);
    nativeValue = (*env)->GetStringUTFChars(env, value, NULL);
    int result = setenv(nativeKey, nativeValue, 1);
    return (jint) result;
}

ambém tenho métodos nativos correspondentes para buscar a variável de ambient

Posso atualizar com êxito o LD_LIBRARY_PATH (essa asserção é baseada na saída da rotina Cgetenv().

Ainda não consigo carregar minha biblioteca nativa. As bibliotecas de terceiros dependentes ainda não foram detectada

Qualquer ajuda / indicação é apreciada. Estou usando o Linux de 64 bits.

Editar

Eu escrevi um SSCE (em C) para testar se o carregador dinâmico está funcionando. Aqui está o SSCE

#include 
#include 
#include 
#include 

int main(int argc, const char* const argv[]) {

    const char* const dependentLibPath = "...:";
    const char* const sharedLibrary = "...";
    char *newLibPath = NULL;
    char *originalLibPath = NULL;
    int l1, l2, result;
    void* handle = NULL;

    originalLibPath = getenv("LD_LIBRARY_PATH");
    fprintf(stdout,"\nOriginal library path =%s\n",originalLibPath);
    l1 = strlen(originalLibPath);
    l2 = strlen(dependentLibPath);
    newLibPath = (char *)malloc((l1+l2)*sizeof(char));
    strcpy(newLibPath,dependentLibPath);
    strcat(newLibPath,originalLibPath);
    fprintf(stdout,"\nNew library path =%s\n",newLibPath);

    result = setenv("LD_LIBRARY_PATH", newLibPath, 1);
    if(result!=0) {
        fprintf(stderr,"\nEnvironment could not be updated\n");
        exit(1);
    }    
    newLibPath = getenv("LD_LIBRARY_PATH");
    fprintf(stdout,"\nNew library path from the env =%s\n",newLibPath);

    handle = dlopen(sharedLibrary, RTLD_NOW);
    if(handle==NULL) {
        fprintf(stderr,"\nCould not load the shared library: %s\n",dlerror());
        exit(1);        
    }
    fprintf(stdout,"\n The shared library was successfully loaded.\n");

    result = dlclose(handle);
    if(result!=0) {
        fprintf(stderr,"\nCould not unload the shared library: %s\n",dlerror());
        exit(1);
    }

    return 0;
}

O código C também não funciona. Aparentemente, o carregador dinâmico não está relendo a variável de ambiente LD_LIBRARY_PATH. Preciso descobrir como forçar o carregador dinâmico a reler a variável de ambiente LD_LIBRARY_PATH.

questionAnswers(3)

yourAnswerToTheQuestion