javafxjavafx-2jnlpaccesscontrolexception

How to open a local file with JavaFX?


I've wrote a mp3 player and works fine in desktop mode (jar file). But when I try to run it via web an AccessControlException is thrown.

I had the same problem with the buttons graphics, and I solved it by uploading the graphics to an image server. Obviously I don't want to do the same with the songs. I want that any user can play their local songs, using a FileChooser.

¿How can I do this?

.....................................................................................................

More details:

The AccessControlException exception occurs here:

try
{
    // f is a File
    listaCanciones.getItems().add(f.getName());     //adding filename to a ListView (works fine)
    mp3Tmp = new Media(f.toURI().toString());       //creating a Media object
    listaReproduccion.add(new MediaPlayer(mp3Tmp)); //creating MediaPlayer object and adding it to a playlist
}

The exception's toString() is:

java.security.AccessControlException: access denied ("java.io.FilePermission" "I:\music\song.mp3" "read")

Solution

  • If you want to access the local filesystem from a jnlp deployed application:

    1. Request appropriate permissions in your jnlp file.
    2. Sign the application.
    3. The user has to accept a dialog prompt to grant those permissions to your application.

    You can find more information in the Java client deployment guide:

    Note: an application which is not deployed via jnlp does not run in a sandbox and does not have the above requirements.

    Oracle supply a FAQ for code signing.