Created
July 1, 2013 04:01
-
-
Save mike-neck/5898270 to your computer and use it in GitHub Desktop.
Using JavaFX as Headless Browser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.mikeneck.jfx.js; | |
import javafx.application.Application; | |
import netscape.javascript.JSObject; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
/** | |
* @author : mike | |
* @since : 13/06/30 | |
*/ | |
public class Main { | |
public static void main(String... args) { | |
Environment environment = new Environment(); | |
try { | |
environment.setUp(); | |
} catch (InterruptedException ignored) { | |
} | |
String script = "(function(){return ['a',2,'c',4,'e'];})();"; | |
JSObject object = JavaScriptExecutor.executeScript(script, JSObject.class); | |
for (int i = 0; i < 5; i++) { | |
System.out.println(object.getSlot(i)); | |
} | |
environment.tearDown(); | |
} | |
static class Environment { | |
private ExecutorService service = Executors.newFixedThreadPool(1); | |
public void setUp () throws InterruptedException { | |
service.execute(new StartApplication()); | |
Thread.sleep(1000L); | |
} | |
public void tearDown () { | |
JavaScriptExecutor.shutdown(); | |
service.shutdown(); | |
} | |
static class StartApplication implements Runnable { | |
@Override | |
public void run() { | |
Application.launch(JavaScriptExecutor.class); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looking for a Headless JavaFX and tried your class. Can you tell me where to find JavaScriptExecutor.class