jsni

I wrote JSNI to detect java version, but it does not work(can not get java version) in the latest browser version such as chrome,IE,Firefox


I used JSNI and it did not work in the latest browsers version(eg.chrome, IE, Firefox)! I wrote this code below :

 public static native boolean detectJavaVersion() /*-{
try {
    var javaVersions = $wnd.deployJava.getJREs();
    alert("Your windows Java version is : " + javaVersions);
    if (javaVersions.length == 0) {
        alert("You have not installed any types of Java in your system");
        return false;
    }
    if (javaVersions < "1.8") {
        alert("Java version is less than 8");
        return false;
    } else {
        alert("Java version is 8 or more than it");
        return true;
    }
}
catch
    (err) {
    var exceptionMsg = err.message;
    alert("Exception is : " + exceptionMsg);
}

}-*/;

I tried to fix it over a week!!! Could someone please gives me an advice. Thanks a lot.


Solution

  • There is no Java in modern browsers (Chrome, Firefox, Edge, Safari), which is probably why your code fails.

    You can still write Java code and let GWT compile it into JavaScript, that way it can run in the browser. The Java features you can use depend on GWT compiler support, not on the browser.