I have made a simple Applet which simply invokes a ant target thorugh batch file on click of button. To do this i am using
ExecTask exec = new ExecTask();
exec.setExecutable("run.bat");
Commandline.Argument arg = exec.createArg();
arg.setValue("-buildfile D:/cloudengine/Applet/build.xml");
exec.execute();
When i run this from eclipse it works properly. But my requirement is to run this from a html page so i have created a simple html with applet tag
<APPLET ALIGN="CENTER" CODE="HtmlAntTest.class" WIDTH="800" HEIGHT="500"></APPLET>
But in browser's java console 开发者_开发问答i get below exception on click of button
Exception in thread "AWT-EventQueue-2" java.lang.ExceptionInInitializerError
at org.apache.tools.ant.taskdefs.ExecTask.<init>(ExecTask.java:72)
.
.
.
Caused by: java.security.AccessControlException: access denied (java.util.PropertyPermission file.encoding read)
Any pointers would be of great help. Thanks in advance
You need to grant additional rights to the applet. It is all explained in detail here: http://java.sun.com/developer/onlineTraining/Programming/JDCBook/appA.html
As das_weezul commented, the applet will require elevated privileges to do this. While changing policy files is one way to achieve that, it is error prone and impractical for deployment.
To get an applet trusted at time of deployment, it will be necessary to:
- Put the classes in a Jar file (see Packaging Programs in JAR Files for details).
- Digitally sign the Jar file (see Signing and Verifying JAR Files for details).
- Get the end user to OK the code when prompted to trust it.
It takes a little time to set up code signing in a build file, but once done correctly it can be forgotten.
精彩评论