gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 13:20:00 27 4
gpt4 key购买 nike

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

图片 (字符串 url, boolean 值 backgroundLoading)

其中 backgroundLoading 设置为 true

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

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

我已尝试将 backgroundLoading 切换为 false 并尝试从其他提供图像访问权限的网站访问 URL。我什至尝试将 URL 的协议(protocol)属性从“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;
}

ViewController - setCurrentImage():

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

最佳答案

感谢@jewelsea,我发现在使用 javafx-maven-plugin 构建应用程序时,我需要添加 jdk.crypto.ec 作为模块选项.看这个answer了解详情。

在 Eclipse 中使用 OpenJDK 11 并从源代码运行时,它工作正常,但通过 jlink 构建 JRT 镜像时,默认情况下必须省略某些模块,例如 jdk.crypto.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>

关于从构建的 JRT 模块运行应用程序时,从 URL 构造的 JavaFX 11 javafx.scene.image 抛出 SSLHandshakeException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57779579/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com