JavaFx:使用webengine在服务器程序中获取javascript呈现的dom
在服务器程序(意味着没有安装X)中,我真的只想加载一个包含一些javascript的html站点,并获得呈现的dom。我想用一个静态函数来实现这一点。我的问题是我无法连接/完成线程JavaFx:使用webengine在服务器程序中获取javascript呈现的dom,java,javafx,Java,Javafx,在服务器程序(意味着没有安装X)中,我真的只想加载一个包含一些javascript的html站点,并获得呈现的dom。我想用一个静态函数来实现这一点。我的问题是我无法连接/完成线程 package svg; import javafx.application.Application; import javafx.application.Platform; import javafx.beans.value.ChangeListener; import javafx.beans.value.Ob
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");
}
}
封装svg;
导入javafx.application.application;
导入javafx.application.Platform;
导入javafx.beans.value.ChangeListener;
导入javafx.beans.value.observeValue;
导入javafx.concurrent.Worker;
导入javafx.scene.web.WebEngine;
导入javafx.scene.web.WebView;
导入javafx.stage.stage;
导入kic.engine.util.DomUtils;
导入javafx.embed.swing.JFXPanel;
公共类呈现扩展了应用程序{
private static final JFXPanel Uffused=new JFXPanel();//我真的需要这个吗?只是为了避免“工具箱未初始化”
公共静态void main(字符串[]args)抛出InterruptedException{
//发射(args);
编译();
系统输出打印项次(“停止”);
}
public static void compile()引发InterruptedException{
线程t=新线程(){
@凌驾
公开募捐{
new Render().start(new Stage());//编辑:复制/粘贴错误
}
};
平台。runLater(t);
t、 join();//永远不要到这里!
}
公共作废开始(最终阶段初级阶段){
最终WebView WebView=新WebView();
final WebEngine=webView.getEngine();
//最终WebEngine=新WebEngine();
//engine.documentProperty().addListener(new ChangeListener(){@Override public void changed(ObservalEvalue)最后,它是一个错误:最后,它是一个错误:修复版本/s Lombard[10380]Priority Major[3]修复版本/s Lombard[10380]Priority Major[3]