0

我正在尝试在网页中嵌入 Java FX 音乐播放器。此 JavaFX 应用程序在 Web 启动模式下运行良好。但是当我尝试在 web 模式下运行它或尝试在构建后访问它的网页时,它给了我 AccessControlException。错误信息是这样的:

    Match: beginTraversal
Match: digest selected JREDesc: JREDesc[version 1.6+, heap=-1--1, args=null, href=http://java.sun.com/products/autodl/j2se, sel=false, null, null], JREInfo: JREInfo for index 0:
    platform is: 1.7
    product is: 1.7.0_13
    location is: http://java.sun.com/products/autodl/j2se
    path is: C:\Program Files\Java\jre7\bin\javaw.exe
    args is: null
    native platform is: Windows, x86 [ x86, 32bit ]
    JavaFX runtime is: JavaFX 2.2.5 found at C:\Program Files\Java\jre7\
    enabled is: true
    registered is: true
    system is: true

    Match: ignoring maxHeap: -1
    Match: ignoring InitHeap: -1
    Match: digesting vmargs: null
    Match: digested vmargs: [JVMParameters: isSecure: true, args: ]
    Match: JVM args after accumulation: [JVMParameters: isSecure: true, args: ]
    Match: digest LaunchDesc: file:/C:/Users/lenovo/Documents/NetBeansProjects/MusicPlay/dist/MusicPlay.jnlp
    Match: digest properties: []
    Match: JVM args: [JVMParameters: isSecure: true, args: ]
    Match: endTraversal ..
    Match: JVM args final: 
    Match: Running JREInfo Version    match: 1.7.0.13 == 1.7.0.13
     Match: Running JVM args match: have:<>  satisfy want:<>
java.security.AccessControlException: access denied ("java.util.PropertyPermission" "user.dir" "read")
    at java.security.AccessControlContext.checkPermission(Unknown Source)
    at java.security.AccessController.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)
    at java.lang.System.getProperty(Unknown Source)
    at java.io.Win32FileSystem.getUserPath(Unknown Source)
    at java.io.Win32FileSystem.resolve(Unknown Source)
    at java.io.File.getAbsolutePath(Unknown Source)
    at java.io.File.getAbsoluteFile(Unknown Source)
    at java.io.File.toURI(Unknown Source)
    at musicplay.MusicPlay.start(MusicPlay.java:90)
    at com.sun.javafx.applet.FXApplet2$1.run(FXApplet2.java:131)
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:176)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:176)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
    at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
    at java.lang.Thread.run(Unknown Source)
CacheEntry[file:/C:/Users/lenovo/Documents/NetBeansProjects/MusicPlay/dist/MusicPlay.jnlp]: updateAvailable=true,lastModified=Mon Feb 04 18:25:32 IST 2013,length=948
CacheEntry[file:/C:/Users/lenovo/Documents/NetBeansProjects/MusicPlay/dist/MusicPlay.jnlp]: updateAvailable=true,lastModified=Mon Feb 04 18:25:32 IST 2013,length=948
CacheEntry[file:/C:/Users/lenovo/Documents/NetBeansProjects/MusicPlay/dist/MusicPlay.jar]: updateAvailable=false,lastModified=Mon Feb 04 18:46:10 IST 2013,length=31879
Java Plug-in 10.13.2.20
Using JRE version 1.7.0_13-b20 Java HotSpot(TM) Client VM
User home directory = C:\Users\lenovo
----------------------------------------------------
c:   clear console window
f:   finalize objects on finalization queue
g:   garbage collect
h:   display this help message
l:   dump classloader list
m:   print memory usage
o:   trigger logging
q:   hide console
r:   reload policy configuration
s:   dump system and deployment properties
t:   dump thread list
v:   dump thread stack
x:   clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------

我尝试通过授予以下权限来编辑 .java.policy 文件

    grant codeBase "file:*" {
        permission java.security.AllPermission;
};

但它仍然给了我同样的信息。任何帮助将不胜感激。

4

1 回答 1

0

我自己找到了答案。在网页中嵌入 JavaFX 应用程序时。您的应用程序(或网页)不允许访问本地文件结构。我以前也试图这样做。我正在传递歌曲文件的路径。但实际上您需要将媒体文件托管在某个服务器目录中,例如 Apache 服务器目录。一个网页可以很容易地访问 Apache Server Directory。您需要将媒体文件的 URI 传递到您的应用程序中。例子currentFile="http://localhost/songs/Jaane_Kaise.mp3";

于 2013-02-04T14:45:57.803 回答