java JavaFX应用程序:未找到FXML文件
我将我的应用程序打包为JAR文件。运行java -jar myapp.jar
效果很好。我想在浏览器中运行这个应用程序,所以我使用javapackage
命令创建了JNLP和HTML文件
我已将我的file://
URL列为白名单,启用了用于调试输出的控制台,下面是我看到的:
FXML resource = null
load fxml
java.lang.IllegalStateException: Location is not set.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2438)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2413)
:
相应的代码是:
public class Main extends Application
{
@Override
public void start(Stage stage) {
try {
System.out.println("FXML resource = " + getClass().getResource("Main.fxml"));
FXMLLoader fxml_loader = new FXMLLoader(getClass().getResource("Main.fxml"));
Controller controller = new Controller(stage);
fxml_loader.setController(controller);
System.out.println("load fxml");
Parent root = fxml_loader.load();
:
我已经验证了Main.xml
在jar文件中的位置和名称是否正确(请记住,从java运行jar文件是有效的)
为什么在使用webstart运行应用程序时,Main.fxml
文件不可见?(javaws myapp.jnlp
产生相同的错误)
我是遗漏了什么还是JavaFX&;JNLP
软件:Java 8 u51,Linux Centos 6 64位
更新
我已经签署了我的jar文件,在我的清单中添加了Permissions: sandbox
和Codebase: *
,在我的清单中添加了<security><all-permissions/></security>
。jnlp,将控制面板设置设置为尽可能允许,将我的URL(file:/
)列入白名单无效。由于“安全原因”,我的应用被阻止。这绝非令人沮丧
# 1 楼答案
可能是你的jar文件没有签名吗
见http://docs.oracle.com/javafx/2/deployment/packaging.htm#BABJGFB
也请查看https://docs.oracle.com/javase/tutorial/deployment/jar/signindex.html