JavaFX-无法使用已签名的应用程序访问文件系统 [英] JavaFX - Unable to access file system with signed app
问题描述
我正在开发一个JavaFX应用程序,该应用程序需要访问用户系统上的文件.我知道我的应用程序必须先签名才能拥有这种访问权限,所以我对我的应用程序进行了签名.但是该应用仍会抛出java.security.AccessControlException
I am developing a JavaFX application that needs to access files on the users system. I know that my application must be signed before it could have such access, so i signed my app. But the app still throws java.security.AccessControlException
-应用程序
public class TestApp extends Application
{
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
launch(args);
}
@Override
public void start(Stage primaryStage)
{
primaryStage.setTitle("Hello World!");
StackPane root = new StackPane();
primaryStage.setScene(new Scene(root, 300, 250));
primaryStage.show();
}
public void callJSFunc(JSObject func)
{
File fleExample = new File("F:/myfile.xml");
func.call("call", fleExample.exists());
}
}
然后我继续对应用程序进行签名
Then i went on to sign the app
keytool -genkey -keystore myKeyStore -alias me
keytool -selfcert -keystore myKeyStore -alias me
jarsigner -keystore myKeyStore TestApp.jar me
因此,我从javascript调用了应用程序 callJSFunc
So i called the apps callJSFunc from javascript
function deployIt()
{
dtjava.embed(
{
id: "my2",
url: "TestApp.jnlp",
width: 300,
height: 200,
placeholder: "here"
},
{
javafx: "2.1+",
jvm: "1.6.0+"
},
{
onJavascriptReady: callApp
});
}
function callApp(id)
{
var app = document.getElementById(id);
app.callJSFunc(function(e){ alert(e); });
}
dtjava.addOnloadCallback(deployIt);
但是我的应用程序是在浏览器上输出的
But my app outputed this on the browser
Uncaught Error: java.security.AccessControlException: access denied ("java.io.FilePermission" "F:/myfile.xml" "read")
此外,我在本地主机上测试了该应用程序.我不明白为什么在安装该应用程序后会引发此异常.请问我做错了什么?谢谢
Also, i tested the app on my localhost. I don't understand why its throwing this exception after siging the app. Please what am i doing wrong? Thanks
推荐答案
请勿使用keytool和jarsigner对应用进行签名.
Don't use the keytool and jarsigner to sign the app.
使用 javafx部署,对软件包进行签名,签名并准备好进行部署工具(例如javafxpackager或JavaFX ant任务).
Instead package, sign and ready your app for deployment using the javafx deployment tools such as javafxpackager or the JavaFX ant tasks.
确保您的 jnlp文件请求提升的权限.如果您正在使用JavaFX ant任务,则可以使用 fx:permissions 子句.
Make sure that your jnlp file requests elevated permissions. If you are using the JavaFX ant tasks, you can request JavaFX to generate an appropriate jnlp with elevated permissions using a fx:permissions clause.
这篇关于JavaFX-无法使用已签名的应用程序访问文件系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!