chromiumembedded / java-cef

Java Chromium Embedded Framework (JCEF). A simple framework for embedding Chromium-based browsers in other applications using the Java programming language.
https://bitbucket.org/chromiumembedded/java-cef
Other
655 stars 144 forks source link

Java Web Start not working #280

Closed magreenblatt closed 4 years ago

magreenblatt commented 7 years ago

Original report by Markus Sosnowski (Bitbucket: syncall, GitHub: syncall).


My application is distributed through Java Web Start (javaws). Locally everything works perfect, just after launching it through javaws it will not work anymore. You all are doing a great job here, I really hope I can use your work (without nasty hacks). This should not be a great deal, I am just not a C++ programmer or I would do it myself.

Problem:

Javaws loads Native librarys from a remote jar (Just all native stuff zipped together). It does that by extracting the jar into a cache. This cache directory is kind a added to the java.library.path, so loading the nativelib in java works fine. The problem is, the direcotry is NOT added to the java.library.path property. JavaCEF now reads the property with java Code and passes it to the DLL. While the DLL is found, the DLL can not find the additional stuff like locales, jcef_helper.exe etc.

Solution (I think will work):

If no path is specified look relative to the DLL for all the required resources.

If relaitve paths are not so easy with C++ than they are with Java the current direcotry can be looked up with the following (For windows):

#!c++

char path[MAX_PATH] = "";
    HMODULE hm = NULL;

    if (!GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
        GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
        (LPCSTR)&localFunc,
        &hm))
    {
        int ret = GetLastError();
        fprintf(stderr, "GetModuleHandle returned %d\n", ret);
        return env->NewStringUTF("");
    }

    GetModuleFileName(hm, path, MAX_PATH);
    return env->NewStringUTF(path);

Reproduction

To reproduice the Problem:

  1. Build a sample Application and pack it into a jar
  2. Pack all native stuff into a second jar
  3. Install Webserver (e.g. Apache) and add the two jars to the webpath
  4. Add a JNLP File to the webpath, similar to the following:
    
    #!xml

<?xml version="1.0" encoding="UTF-8"?>

Dynamic Tree Demo Dynamic Team


5. start the application through **javaws http://localhost/myJnlpFile.jnlp**
magreenblatt commented 7 years ago

Original comment by Markus Sosnowski (Bitbucket: syncall, GitHub: syncall).


I found this project: https://github.com/gpakosz/whereami It does exactly the job of findinge the library location (tested on windows / mac). It might be worth using even for normal java (not javaws).

I've used the following code:

#!c++

int dirname_length;
    int length = wai_getModulePath(NULL, 0, &dirname_length);

    char* path = (char*)malloc(length + 1);

    wai_getModulePath(path, length, &dirname_length);
    path[length] = '\0';

    jstring re = env->NewStringUTF(path);
    free(path);
        return re
magreenblatt commented 7 years ago

Original comment by Markus Sosnowski (Bitbucket: syncall, GitHub: syncall).


And the mac files have to be reorganized a bit. It seems javaws does not distribute folders on Mac. So all files have to go in one directory..

magreenblatt commented 6 years ago

Please create a PR with your proposed changes. Instructions are at https://bitbucket.org/chromiumembedded/cef/wiki/ContributingWithGit.md#markdown-header-creating-a-pull-request

magreenblatt commented 6 years ago

Original comment by mlewando (Bitbucket: mlewando, GitHub: mlewando).


Hi guys,

any updates on that? Or maybe you can provide more details about the solution? eg. where to change what code?

magreenblatt commented 4 years ago

Seems like this would be addressed by issue #317 or issue #367. If something is still missing please comment.

magreenblatt commented 4 years ago