问题描述
是否可以使用java.util.Logging并登录到Java Webstart应用程序中的文件?我有以下记录代码:
is it possible to use java.util.Logging and log to a file in a java webstart application?I have the following logging code:
Handler fh = new FileHandler("myapp.log");
Logger.getLogger(MyApp.class.getName()).addHandler(fh);
,但出现以下异常:
java.security.AccessControlException: access denied (java.util.logging.LoggingPermission control)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.util.logging.LogManager.checkAccess(Unknown Source)
at java.util.logging.Handler.checkAccess(Unknown Source)
at java.util.logging.FileHandler.(Unknown Source)
at whoisapiclient.WhoisAPIClientApp.main(WhoisAPIClientApp.java:80)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javaws.Launcher.executeApplication(Unknown Source)
at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
at com.sun.javaws.Launcher.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
推荐答案
访问控制异常是这样的:
The access control exception says this:
权限类的 javadoc 表示:
您所做的事情显然属于控制"权限.
What you are doing clearly falls under the "control" permission.
如果要创建/添加自己的日志处理程序,则需要对应用程序进行签名.
You will need to sign your application if it is to create/add its own log handlers.
顺便说一句,如果您确实设法解决了LoggingPermission("control")
的问题,则在打开日志文件时会遇到另一个访问问题.
Incidentally, if you did manage to work around the LoggingPermission("control")
, you would then run into another access issue in opening the log file.
这两个问题都可以通过对应用程序进行签名来解决.然后,您遇到了用户必须接受/信任您的签名密钥的问题.但这很公平!就Java安全沙箱所知,您正在执行的操作可能会损坏用户的计算机.
Both problems are solved by signing the application. You've then got the problem that the user has to accept / trust your signing key. But that is fair enough! As far as the Java security sandbox can tell, what you are doing could potentially damage the user's machine.
这篇关于webstart应用程序日志记录权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!