JxBrowser无法在JavaFX中部署

时间:2017-08-28 06:54:35

标签: javafx jxbrowser

我使用Tabpane多个浏览器;当我关闭一个标签时,我无法处理主IPC:

public class JxbrowserDemo extends Application {
    @Override
    public void start(Stage primaryStage) {
        setLevel(Level.ALL);
        TabPane tabPane = new TabPane();
        tabPane.getTabs().add(createBrowserTab());
        tabPane.getTabs().add(createBrowserTab());
        StackPane pane = new StackPane();
        pane.getChildren().add(tabPane);
        Scene scene = new Scene(pane, 500, 400);
        primaryStage.setTitle("JxBrowser: JavaFX - Hello World");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public Tab createBrowserTab() {
        Tab tab = new Tab("baidu");
        Browser browser = new Browser();
        BrowserView browserView = new BrowserView(browser);

        tab.setOnClosed(new EventHandler<Event>() {
            @Override
            public void handle(Event event) {
                //last tag close throw exception
                //
                browser.dispose();
            }
        });

        tab.setContent(browserView);
        browser.loadURL("www.google.com");
        //tabPane.getTabs().add(tab);
        //browserArrayList.add(browser);
        return tab;
    }

    @Override
    public void stop() throws Exception {
        //dispose here Success
        /*browserArrayList.forEach(t->{
            t.dispose();
        });*/
        super.stop();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

日志:

02:42:22 信息: Shutting down event queue...
02:42:22 信息: Shutting down event queue... [DONE]
02:42:22 信息: Shutting down event queue...
02:42:22 信息: Shutting down event queue... [DONE]
02:42:22 信息: Channel has been disconnected: SocketChannel{cid=1, bid=1, type=Render}
02:42:22 信息: Channel is disconnected: SocketChannel{cid=1, bid=1, type=Render}
02:42:22 信息: Shutting down event queue...
02:42:22 信息: Shutting down event queue... [DONE]
02:42:22 信息: Shutting down event queue...
02:42:22 信息: Shutting down event queue... [DONE]
02:42:22 信息: IPC connection has been closed. Connection ID: 466160688
02:42:22 信息: Pending IPC connections: 2
02:42:22 信息: Channel has been disconnected: SocketChannel{cid=1, bid=1, type=Browser}
02:42:22 信息: Channel is disconnected: SocketChannel{cid=1, bid=1, type=Browser}
02:42:22 信息: Stopping IPC...
02:42:22 信息: Stopping main channel...
02:42:22 信息: IPC connection has been closed. Connection ID: 466160864
02:42:22 信息: Pending IPC connections: 1
02:42:22 详细: WRITE: ShutdownMessage{type=Shutdown, uid=175, SocketInfo{cid=0, bid=-1, channelType=Main

挂在这里。

大约五分钟后它会抛出异常:

02:42:22 详细: WRITE: ShutdownMessage{type=Shutdown, uid=175, SocketInfo{cid=0, bid=-1, channelType=Main}
Exception in thread "JavaFX Application Thread" com.teamdev.jxbrowser.chromium.internal.ipc.IPCException: Failed to execute shutdown post message.
02:44:22 信息: Shutting down event queue...
02:44:22 信息: Shutting down event queue... [DONE]
02:44:22 信息: Shutting down event queue...
02:44:22 信息: Shutting down event queue... [DONE]
02:44:22 信息: Channel has been disconnected: SocketChannel{cid=0, bid=-1, type=Main}
02:44:22 信息: IPC connection has been closed. Connection ID: 466161040
02:44:22 信息: Pending IPC connections: 0
02:44:22 信息: Chromium process exit code 0

2 个答案:

答案 0 :(得分:1)

尝试在非JavaFx应用程序线程中配置Browser实例:

        tab.setOnClosed(new EventHandler<Event>() {
        @Override
        public void handle(Event event) {
            //last tag close throw exception
            //
            new Thread(new Runnable() {
                @Override
                public void run() {
                    browser.dispose();
                }
            }).start();
        }
    });

答案 1 :(得分:1)

您必须根据此JXBrowser文章检测操作系统,然后以适当的方式关闭它https://jxbrowser.support.teamdev.com/support/solutions/articles/9000013069-lightweight-or-heavyweight

我的策略:

command-runner.jar