使用jpackage打包JavaFX应用后启动报错:无法启动JVM
关于JavaFX应用jpackage打包后启动失败的问题
打包使用的jpackage命令
.\jpackage.exe --input C:\Users\My\Documents\NetBeansProjects\MyFX\target\ --dest C:\Users\My\Documents\NetBeansProjects\MyFX\ --name "MyFX" --main-jar C:\Users\My\Documents\NetBeansProjects\MyFX\target\MyFX-2.0.jar --main-class my.myfx.App --module-path 'C:\Program Files\Java\jmods\\' --add-modules javafx.controls,javafx.fxml,java.sql --win-console
启动报错信息
启动生成的程序时提示报错:Unable to Launch JVM,控制台输出中包含错误栈信息:Circular loading of URL stream handler providers detected
主类MyFX.App代码
package my.myfx; public class App extends javafx.application.Application { public static javafx.scene.image.Image loadingImg,tickImg,appIconImg; public static javafx.scene.image.ImageView loading,tick,appIcon; private static javafx.scene.Scene scene; @Override public void start(javafx.stage.Stage stage) throws java.io.IOException { try{ appIcon=new ImageView(); appIconImg=new Image(getClass().getResource("icons/icon.png").toURI().toString()); appIcon.setImage(appIconImg); loading=new ImageView(); loadingImg=new Image(getClass().getResource("icons/loading.gif").toURI().toString()); loading.setImage(loadingImg); javafx.concurrent.Task<Exception>work=new javafx.concurrent.Task<>(){ @Override protected Exception call(){ try{ Thread.sleep(500); //Simulate IO operation }catch(Exception ex){ return ex; } return null; } }; new Thread(work).start(); scene = new javafx.scene.Scene(new javafx.fxml.FXMLLoader(getClass().getResource("fxml/main.fxml")).load(), 640, 480); stage.setScene(scene); stage.setMaximized(true); stage.setTitle("MyFX"); stage.getIcons().add(appIconImg); stage.show(); work.setOnSucceeded(e->{ try{ if(work.get()==null){ System.out.println("Folders initialized"); tick=new ImageView(); tickImg=new Image(getClass().getResource("icons/tick.png").toURI().toString(),true); tick.setImage(tickImg); }else{ System.out.println(work.get()); } }catch(Exception ex){ System.out.println(ex); } }); stage.setOnCloseRequest((javafx.stage.WindowEvent t) -> { javafx.application.Platform.exit(); System.exit(0); }); }catch(Exception ex){ System.out.println(ex); } } public static void main(String[] args) { launch(); } static void setRoot(){ try{ scene.setRoot(new javafx.fxml.FXMLLoader(App.class.getResource("fxml/main.fxml")).load()); }catch(Exception ex){ System.out.println(ex); } } }
(注:原代码缺失extends javafx.application.Application,已补充以保证代码完整性)
疑问
- 是否需要添加更多库或JMod?
- 该循环加载报错与启动失败问题有何关联?
内容的提问来源于stack exchange,提问作者Javauser
相关产品推荐
相关产品推荐

