0

我正在使用 JavaFX 2.2 开发人员预览版(Build 19)的新“本机打包”功能。我可以成功构建安装程序(.exe)。但是,一旦我启动了使用该安装程序部署的 JavaFX 应用程序,我执行的每个 HTTPS 请求都会出现以下异常:

javax.net.ssl.SSLKeyException: RSA premaster secret error
    at sun.security.ssl.RSAClientKeyExchange.<init>(RSAClientKeyExchange.java:114)
...
Caused by: java.security.NoSuchAlgorithmException: SunTlsRsaPremasterSecret KeyGenerator not available
    at javax.crypto.KeyGenerator.<init>(KeyGenerator.java:158)
...

当我从 Eclipse 启动我的代码时,或者当我启动应用程序表单命令行时,一切正常。该问题仅在我启动安装程序部署的应用程序时出现。

我怎样才能避免这个异常?

我写了一些演示代码来显示问题。

Java FX 应用程序:

package dk.bundleDemo;

import java.net.HttpURLConnection;
import java.net.URL;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import org.apache.log4j.Logger;

public class RunBundleTest extends Application {

    private static Logger log = Logger.getLogger(RunBundleTest.class);

    @Override
    public void start(Stage primaryStage) throws Exception {
        AnchorPane root = new AnchorPane();
        Label statusLable = new Label();
        String statusText = "Status is: ";
        root.getChildren().add(statusLable);
        Scene scene = new Scene(root, 200, 200);
        primaryStage.setScene(scene);
        primaryStage.show();

        try {
            URL url = new URL("https://www.google.com");
            HttpURLConnection conn = (HttpURLConnection)url.openConnection();
            Integer responseCode = conn.getResponseCode();
            statusLable.setText(statusText + responseCode.toString());
        }
        catch (Exception e) {
            log.error("error while connecting", e);
        }
    }

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

用于创建安装程序的 Ant 脚本:

<project name="JavaFXSample" default="build and deploy" basedir="."
         xmlns:fx="javafx:com.sun.javafx.tools.ant">

    <target name="build and deploy">

        <property name="applet.width" value="500"/>
        <property name="applet.height" value="500"/>
        <property name="application.title" value="BundleTest"/>
        <property name="application.vendor" value="TestVendor"/>
        <property name="build.classes.dir" value=".\bin"/>
        <property name="basedir" value="."/>
        <property name="dist.dir" value="..\..\BundleTest"/>
        <property name="javafx.lib.ant-javafx.jar" value="C:\Program Files\Java\jdk1.7.0_06\lib\ant-javafx.jar"/>


        <taskdef resource="com/sun/javafx/tools/ant/antlib.xml"      
                uri="javafx:com.sun.javafx.tools.ant"
                classpath="${javafx.lib.ant-javafx.jar}"/>

        <fx:application id="bundleTest"
                name="bundleTest"
                mainClass="dk.bundleDemo.RunBundleTest"
                />

        <fx:resources id="appRes">
            <fx:fileset dir="lib" includes="*.jar"/>
        </fx:resources> 

        <fx:jar destfile="lib\RunBundleTest.jar">
            <fx:application refid="bundleTest"/>

            <fx:resources refid="appRes"/>

            <manifest>
                <attribute name="Implementation-Vendor"
                        value="${application.vendor}"/>
                <attribute name="Implementation-Title"
                        value="${application.title}"/>
                <attribute name="Implementation-Version" value="1.0"/>
            </manifest>

            <fileset dir="${build.classes.dir}"/>
        </fx:jar>


        <fx:deploy width="${applet.width}" height="${applet.height}"
                outdir="${basedir}/${dist.dir}" embedJNLP="true"
                outfile="${application.title}"
                nativeBundles="all"
                >

            <fx:application refId="bundleTest"/>

            <fx:resources refid="appRes"/>            

            <fx:info title="${application.title}"
                    vendor="${application.vendor}"/>

        </fx:deploy>

</target>
</project>

有关 JavaFX 原生打包的更多信息: https ://blogs.oracle.com/talkingjavadeployment/entry/native_packaging_for_javafx

4

1 回答 1

3

问题是 JavaFX 2.2 开发人员预览中的一个错误:http: //javafx-jira.kenai.com/browse/RT-23889

于 2012-08-15T07:46:24.903 回答