Search code examples
javajava-web-startjava-security

Java Web Start app logging permission denied


My java app runs fine stand-alone. But when I run it as a Java Web Start app, it starts up but fails when I click a certain button. I couldn't figure out how to debug it so thought I'd add logging. That caused permission denied error and wouldn't even start up.

To try and solve that problem, I added

permission java.util.logging.LoggingPermission "control"

to the C:\Program Files\Java\jre1.8.0-171\lib\security\java.policy file and the C:\Program Files\Java\jdk1.8.0-171\jre\lib\security\java.policy file. Restarted the Apache HttpServer and tried again. Same result.

Next I added the following line to the same two files:

permission java.security.AllPermission;

Same result.

Next I self-signed the jar file. Same result.

Next I added

<security><all-permissions/></security>

to the dynamically generated .jnlp file. This time I got a new message: "unsigned application requesting unrestricted access to system"

A jarsigner verify confirms the jar file has been signed:

jarsigner -verify myjarfile.jar

jar verified.

I don't know what else to try. Suggestions?


Solution

  • First of all, there needed to be a ";" after "control". I don't know if that would have fixed the problem in itself but I found a parsing error for it in the log file. Meanwhile, I had changed all my "logger" commands back to System.out.println commands.

    Next I checked "Enable tracing" and "Enable logging" in the Advanced tab of the Java Control Panel.

    Then, in a DOS shell, I navigated to the location of myjnlp.jnlp file and entered the following commands:

    set JAVAWS_TRACE_NATIVE=1
    set JAVA_TOOL_OPTIONS=-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000
    javaws myjnlp.jnlp
    

    That caused log files to be created in the home directory at C:\Users\Greg\AppData\LocalLow\Sun\Java\Deployment\log where I could then see what was going on.

    Unfortunately a new problem. See code below:

        File source = new File(localFilename);
        File dest = new File("C:/E360/CadIntegration/" +localFilename);
        try {
            Files.copy(source.toPath(),dest.toPath());
            msg = "Because IP was blank, file was copied to C:/E360/CadIntegration";
        } catch (IOException ex) {
            msg = "problem copying " +source.toPath() +" to " +dest.toPath();
            System.out.println("uploadCadChanges: " +msg +", IOException is "+ex.getMessage());
        }
    

    If I run the app using javaws, it works perfectly, the file is copied over successfully. But if I run it from the web page it fails with the IOException and ex.getMessage() just says "CadChanges.txt". Real helpful.

    I found the reason. When run from a web page, the current working directory is changed to current dir = C:\Program Files (x86)\Google\Chrome\Application\67.0.3396.99 but when run from javaws, it isn't. The solution was to pass the current directory to the .jnlp file via an argument tag and have the app change the cwd to it.