1

In a server program (means no X installed) I really just want to load a html site containing some javascript and get the rendered dom. I want to do this in the way of using a static function. My problem is that I am not able to get the threads joined/finished.

package svg;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import kic.engine.util.DomUtils;
import javafx.embed.swing.JFXPanel;

public class Render extends Application {
    private static final JFXPanel USELESS = new JFXPanel(); // do I really need this? just to avoid "Toolkit not initialized"

    public static void main(String[] args) throws InterruptedException { 

        //launch(args); 
        compile();
        System.out.println("stop");
    }

    public static void compile() throws InterruptedException {
        Thread t = new Thread() {
            @Override
            public void run() {
                new Render().start(new Stage()); //EDIT: copy/paste mistake
            }
        };

        Platform.runLater(t);
        t.join(); // never get here!
    }

    public void start(final Stage primaryStage) {
        final WebView webView = new WebView();
        final WebEngine engine = webView.getEngine();
        //final WebEngine engine = new WebEngine();

        //engine.documentProperty().addListener( new ChangeListener<Document>() { @Override public void changed(ObservableValue<? extends Document> prop, Document oldDoc, Document newDoc) {
        engine.getLoadWorker().stateProperty().addListener(new ChangeListener<Worker.State>() { 
            public void changed(ObservableValue ov, Worker.State oldState, Worker.State newState) {
                if (newState == Worker.State.SUCCEEDED) {
                    System.out.println(DomUtils.getDocumentString(engine.getDocument()));

                    primaryStage.close();
                    //Platform.setImplicitExit(true);

                    Platform.exit();  // platform will not exit ... it will exit if I use Application.launch(), but throws an error: java.lang.IllegalStateException: Attempt to call defer when toolkit not running
                    System.out.println("after exit");
                } 
            }
        });

        engine.load("file:///myD3.html");
        System.out.println("after load");
    }
}

Can someone help me getting a static function just call the webengine and return the dom.

EDIT: Even a Thread.currentThread().getThreadGroup().interrupt(); will not stop the Application from running only a System.exit(1) does, but I do not want to shutdown JVM.

1 Answer 1

1

Finally it turns out, it is a Bug: https://bugs.openjdk.java.net/browse/JDK-8092869

Sign up to request clarification or add additional context in comments.

1 Comment

Fix Version/s Lombard [ 10380 ] Priority Major [ 3 ]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.