3

I'm building a swing application which will be distributed using java webstart. It is kind of java editor where my app's users will be able to compile java source code.

The issue is -

JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();

It works fine in the dev env. But when I'm deploying my app using webstart, then in the client side, it returns null.It is because of the fact that my app is running on JRE instead of JDK. [System.getProperty("java.home") points to JRE]

To overcome this issue, I had followed the suggestion mentioned in the following SO thread.

I'm pointing java.home property to JDK's installation directory.

System.setProperty("java.home","C:\\DevEnv\\java");

Now ToolProvider.getSystemJavaCompiler();returns valid compiler object, but I'm getting the following exception while compiling the java code with it. It is actually while calling the getStandardFileManager method of the compiler object.

Code

    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    System.out.println("Compiler - " + compiler);

    if(compiler!=null){
        MyDiagnosticListener c = new MyDiagnosticListener(logWindow);
        StandardJavaFileManager fileManager = compiler.getStandardFileManager(c, Locale.ENGLISH, null);

        Iterable<String> options = Arrays.asList("-d", CLASS_OUTPUT_DIR);
        JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager,
                            c, options, null, files);
        Boolean result = task.call();
}

Exception -

enter image description here

Please help me to resolve this issue.

ADD JNLP

<?xml version="1.0" encoding="utf-8"?> 
<jnlp spec="1.0+" codebase="http://<dynamic-ip>:8080/" href="ProjT.jnlp">
    <information>
        <title>Tectra</title>
        <vendor>Manas Kumar Mukherjee</vendor>
        <homepage href="http://<dynamic-ip>:8080/" />
        <description>Testing Testing</description>
    </information>
    <security>
        <all-permissions/>
    </security>
    <resources>
        <j2se version="1.6+" />
        <jar href="Tools.jar" />
...
        <jar href="log4j-1.2.16.jar" />
    </resources>
    <application-desc main-class="com.ui.DevMain" />
</jnlp>

Thanks

Community
  • 1
  • 1
Manas Mukherjee
  • 5,270
  • 3
  • 18
  • 30
  • Have you properly signed your applet? Otherwise it will only have very limited permissions on the client machine! – Gyro Gearless Sep 17 '13 at 20:50
  • yes I did. The swing application is working properly.In the JNLP file, I have set the all 'all-permissions' in security attribute. Compilation process is working fine in my dev env(using eclipse). Thanks – Manas Mukherjee Sep 17 '13 at 20:52
  • 1) Be sure to check the JNLP using [JaNeLA](http://pscode.org/janela/). 2) *"I'm pointing java.home property to JDK's installation directory."* How is that supposed to work for your users? Do you expect that they change the properties themselves? 3) Please don't post screenshots of textual information. Copy/paste the **text**. Not only is it less bytes for others to download/see, but is searchable. – Andrew Thompson Sep 18 '13 at 19:36
  • 1)I verified the JNLP using Janela. I didn't find any issue thr. I'm adding the JNLP in the post. 2) In the client side, I'm executing System.getenv() to get JAVA_HOME and setting it in java.home property [ System.setProperty("java.home",USERS_JAVA_HOME);]. 3) I couldn't copy the exception trace from the webstart's log window. That's y pasted it as image. I understand, it is not good. Thanks for ur suggestion. – Manas Mukherjee Sep 18 '13 at 20:24

1 Answers1

0

The error should help describe exactly what is wrong.

"AccessControlContext.checkPermission" fails with "AccessControlException: access denied".

Check which user the process is being run with when the JVM for this application starts. Ensure the user that starts the JVM is a super-user admin with all rights to the complete directory tree, etc and see if that fixes it. Then scale down the access rights until it breaks again and you will have the right permission level.

Darrell Teague
  • 4,132
  • 1
  • 26
  • 38
  • I've full admin privilege in my system. It is working from eclipse. But when I'm deploying using java web-start and accessing the same using browser, then only I'm getting this issue. Are you suggesting me to use a custom policy(-Djava.security.policy) with all permission ? I don't know how to mention that in the jnlp file. From my app, I'm changing the java.home property to point JDK. is that causing any issue ? Thanks in adv. – Manas Mukherjee Sep 18 '13 at 19:25
  • When running via Java web-start, it will run as a different user for that process (system-user), which likely does not have sufficient permissions for accessing the resource. Run from console as the system admin (not web-start) to see if that resolves. – Darrell Teague Oct 03 '13 at 09:35