我正在使用WebView打开网页,没有什么不常见的。对于许多网页来说,没有任何问题,但对于一些网页崩溃的应用程序,实际上JVM崩溃。
复制步骤:
1创建新的Application类'Test.java'
import javafx.application.Application;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import java.net.URL;
public class Test extends Application {
@Override
public void start(Stage stage) {
try {
FXMLLoader loader = new FXMLLoader();
URL resource = Test.class.getResource("Test.fxml");
loader.setLocation(resource);
loader.setController(new TestController());
BorderPane rootLayout = loader.load();
Scene scene = new Scene(rootLayout, 1200, 800);
stage.setScene(scene);
stage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void stop() {
Platform.exit();
System.exit(0);
}
public static void main(String[] args) {
Application.launch(args);
}
}
2创建加载有问题网址的新控制器'TestController.java'
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.web.WebView;
import java.net.URL;
import java.util.ResourceBundle;
public class TestController implements Initializable {
@FXML
private WebView webView;
@Override
public void initialize(URL location, ResourceBundle resources) {
webView.getEngine().load("http://programmers.stackexchange.com/questions/233053/why-were-default-and-static-methods-added-to-interfaces-in-java-8-when-we-alread");
}
}
3使用WebView'Test.fxml'
创建XML<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.*?>
<?import java.lang.*?>
<?import javafx.scene.web.*?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1">
<center>
<WebView fx:id="webView" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
4创建权利文件'entitlements.plist'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>
5申请权利
我正在使用这些命令:
chmod -R +w /Users/.../Test.app/Contents/PlugIns/Java.runtime
codesign -v -f -s $SIGNER --entitlements /Users/.../entitlements.plist /Users/.../Test.app/Contents/PlugIns/Java.runtime
find /Users/.../Test.app/Contents/ -type f \( -name "*.jar" -or -name "*.dylib" \) -exec codesign --verbose -f -s $SIGNER --entitlements /Users/.../Test/entitlements.plist {} \;
codesign -v -f -s $SIGNER --entitlements /Users/../entitlements.plist /Users/../Test.app/Contents/PlugIns/Java.runtime/Contents/Home/jre/lib/jspawnhelper
codesign -v -f -s $SIGNER --entitlements /Users/../entitlements.plist /Users/ondrej/../Test.app
运行Test.app
您将看到,当WebView加载URL时,它会显示已加载的页面一段时间,然后应用程序崩溃。
我试图禁用JavaScript,但它没有帮助。应用程序仍在崩溃。
你知道根本原因是什么吗?
以下是来自Mac控制台的日志:http://pastebin.com/wwXecvra