如何在java中多次调用launch()
2022-09-03 17:23:34
如何在java中多次调用launch()我被赋予一个例外,如“MAIN:java.lang.IllegalStateException中的错误:应用程序启动不得调用多次”
我已经在我的java应用程序中创建了休息cleint,当请求来临时,它调用javafx并在完成webview操作后打开webview,使用Panform.exit()方法关闭javafx窗口。当第二个请求来时,我得到这个错误如何重新设置这个错误。
JavaFx Application Code:
public class AppWebview extends Application {
public static Stage stage;
@Override
public void start(Stage _stage) throws Exception {
stage = _stage;
StackPane root = new StackPane();
WebView view = new WebView();
WebEngine engine = view.getEngine();
engine.load(PaymentServerRestAPI.BROWSER_URL);
root.getChildren().add(view);
engine.setJavaScriptEnabled(true);
Scene scene = new Scene(root, 800, 600);
stage.setScene(scene);
engine.setOnResized(new EventHandler<WebEvent<Rectangle2D>>() {
public void handle(WebEvent<Rectangle2D> ev) {
Rectangle2D r = ev.getData();
stage.setWidth(r.getWidth());
stage.setHeight(r.getHeight());
}
});
JSObject window = (JSObject) engine.executeScript("window");
window.setMember("app", new BrowserApp());
stage.show();
}
public static void main(String[] args) {
launch(args);
}
RestClient 方法:调用 JavaFX 应用程序
// method 1 to lanch javafx
javafx.application.Application.launch(AppWebview.class);
// method 2 to lanch javafx
String[] arguments = new String[] {"123"};
AppWebview .main(arguments);