0

I am getting an exception while I am trying to write a log using log4j.

Here is the exception that is thrown:

java.security.AccessControlException: access denied ("java.io.FilePermission" "D:\appletServer\bqapplet.log" "write")
     at java.security.AccessControlContext.checkPermission(Unknown Source)
     at java.security.AccessController.checkPermission(Unknown Source)
     at java.lang.SecurityManager.checkPermission(Unknown Source)
     at sun.plugin2.applet.AWTAppletSecurityManager.checkPermission(Unknown Source)
     at java.lang.SecurityManager.checkWrite(Unknown Source)
     at java.io.FileOutputStream.<init>(Unknown Source)
     at java.io.FileOutputStream.<init>(Unknown Source)
     at org.apache.log4j.FileAppender.setFile(FileAppender.java:294)
     at org.apache.log4j.RollingFileAppender.setFile(RollingFileAppender.java:207)
     at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:165)
     at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:307)
     at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:172)
     at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:104)
     at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:842)
     at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:768)
     at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:648)
     at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:514)
     at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:440)
     at com.bqurious.applet.CommandExecutor.<init>(CommandExecutor.java:41)
     at com.bqurious.applet.BqAppletMainAppender.waitForConnections(BqAppletMainAppender.java:604)
     at com.bqurious.applet.BqAppletMainAppender.run(BqAppletMainAppender.java:195)
     at java.lang.Thread.run(Unknown Source)
  Error! - java.security.AccessControlException: access denied ("java.io.FilePermission" "D:\appletServer\bqapplet.log" "write")
Ben Green
  • 3,953
  • 3
  • 29
  • 49
Om Prakash
  • 793
  • 7
  • 14

1 Answers1

0

Applets will per default run in a sandboxed environment. In order to allow it to access local files you will have to sign it. Depending on your use case, a different approach may be to log to standard out (which will be available on the java console).

There is a tutorial at Oracle where you can read more about What Applets Can and Cannot Do.

Per Huss
  • 4,755
  • 12
  • 29