当前位置: 首页 > 知识库问答 >
问题:

从URL构造的JavaFX 11 javafx.scene.image在从构建的JRT模块运行应用程序时抛出SSLHandshakeException

华子航
2023-03-14

我正在开发一个javaFX 11应用程序,它使用javafx.scene.image类从URL加载图像:

图像​(字符串url,布尔背景加载)

其中backgroundLoading设置为true。

从我的 Eclipse IDE(使用 Maven)运行时,应用程序运行良好。但是,当应用程序构建为模块化 (JRT) 应用程序并且我运行启动器来测试构建时,我的 Image 对象不会从其分配的 URL(https 协议)加载,而是指示错误。返回的异常为:

java.util.concurrent.ExecutionException: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure

我尝试将背景加载切换到 false,并尝试从其他提供图像访问的站点的 URL。我什至尝试将URL的协议属性从“https”更改为“http”。结果还是一样。

我有一个ImageHandler类用于处理javafx.scene.image对象的构造和设置,还有另一个类使用ImageHandler设置javafx.scene.image.ImageView对象的图像(通过使用侦听器检查后台加载何时完成)。

我无法提供完整的代码来重现该问题,但以下是上述类的一些片段:

ImageHandler-getImage():

public Image getImage() {
    if (this.image == null || this.imageHadErrorLoading()) {
        this.imageUrl = String.format(Settings.GATHERER_URL + ImageHandler.QUERY_DATA, this.multiverseId);
        LoggerUtil.logger(this).log(Level.INFO, String.format("URL for image: %s", this.imageUrl));
        try {
            this.image = new Image(this.imageUrl, this.backgroundLoading);
            this.setImageError(false);  
        } catch (Exception e) {
            LoggerUtil.logger(this).log(Level.SEVERE, String.format("Exception creating new Image: %s", e.toString()));
        }
    }

    return this.image;
}

视图控制器-setMoney tImage():

private void setCurrentImage(int multiverseId) {
    ImageHandler imageHandler;
    imageHandler = new ImageHandler(multiverseId, true);
    Image cardImage = imageHandler.getImage();

    // If the image was previously loaded (successfully), just set the image.
    // Otherwise, use a listener to monitor the loading of the image which
    // eventually sets the image once it has successfully loaded.
    if (imageHandler.imageHasLoaded()) {
        this.cardImageView.setImage(cardImage);
        LoggerUtil.logger(this).log(Level.INFO, String.format("Multiverse ID %d: Image cached....getting image....", multiverseId));
    } else {
        // This listener on the image's progress is used to set the Image View when the image has finally loaded. In the meantime,
        // the Image View will continue to display the "placeholder" image.
        cardImage.progressProperty().addListener(new ChangeListener<Number>() {
            @Override
            public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
                double cardProgress = (double) newValue;
                if (cardProgress == 1.0) {
                    if (cardImage.isError()) {
                        cardImageView.setImage(imageHandler.getErrorImage());
                        LoggerUtil.logger(this).log(Level.SEVERE, String.format("Multiverse ID %d: Error loading image.", multiverseId));
                        LoggerUtil.logger(this).log(Level.SEVERE, String.format("Image exception was: %s", cardImage.getException().getMessage()));
                        LoggerUtil.logger(this).log(Level.SEVERE, String.format("Image exception was: %s", cardImage.getException()));
                    } else {
                        cardImageView.setImage(cardImage);
                        imageHandler.setImageLoaded(true);
                        LoggerUtil.logger(this).log(Level.INFO, String.format("Multiverse ID %d: Image loaded successfully! Image URL: %s", multiverseId, cardImage.getUrl()));
                    }
                }
            }
        });
    }

预期结果:应用程序从构建的JRT模块运行时显示图像,并具有与从Eclipse IDE运行时相同的行为。

实际结果:应用程序映像在从构建的 JRT 模块运行时生成 SSLHandshakeException

共有1个答案

赵献
2023-03-14

多亏了@jewelsea我发现在使用javafx-maven-plugin构建应用程序时,我需要添加 jdk.crypto.ec 作为模块选项。有关详细信息,请参阅此答案。

当在Eclipse中使用OpenJDK11并从源代码运行时,它工作正常,但某些模块如jdk.crypto。除非特别添加,否则通过jlink构建JRT映像时,默认情况下必须省略ec。

下面是我在我的Maven POM中更新的javafx-maven-plugin定义:

<plugin>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-maven-plugin</artifactId>
    <version>0.0.2</version>
    <configuration>
        <release>11</release>
        <jlinkImageName>thecollector</jlinkImageName>
        <launcher>launcher</launcher>
        <mainClass>thecollector/com.cladge.thecollector.MainApp</mainClass>
        <options>
            <option>--add-modules</option>
            <option>jdk.crypto.ec</option>
        </options>
    </configuration>
</plugin>
 类似资料:
  • 内部没有任何签名配置。

  • 我想从intelliJ运行我的spring-boot应用程序,而不是使用终端,但它不允许,它只是抛出了一大堆错误,而当我从中的终端运行时,应用程序会按预期启动。 通过intelliJ(右上角的run按钮)运行时: 但当我去跑的时候: 在终端中,我的应用程序启动,我可以开始对服务器进行http调用。

  • 当我构建我的应用程序时,我遇到以下错误,请帮助。 运行应用程序时没有错误,制造战争时出错。

  • 我创建了一个phonegap项目,并通过以下方式添加了android平台http://docs.phonegap.com/en/4.0.0/guide_cli_index.md.html#The此文档的命令行界面。当我尝试使用以下命令构建它时: cordova build或cordova build android 我得到了这个错误。

  • 我使用EclipseGradle插件执行了一个gradle构建,并将war文件从build/lib部署到远程服务器上的tomcat上。war文件抛出404,即使tomcat管理器将war标识为已部署。看到日志后,似乎Spring应用程序根本没有启动。 日志: 更新: 在更改log4j属性后,多亏了Stefan,当我试图部署我的war文件时,我发现了以下错误。

  • 我们使用带有Log4j的springaop来登录我们的应用程序。我在应用程序中实现了@Before、@After、@posterhrowing建议。但我面临以下问题: 当任何异常在catch块中被捕获时,它不会调用@afterhrowing通知来打印错误堆栈跟踪。 我想为catch块中捕获的异常打印“错误堆栈跟踪”。意味着无论何时在try块中发生任何异常并被catch捕获,都应该调用一些建议来打印