构建jar文件后,JavaFX 2.2生成的图像未显示 [英] JavaFX 2.2 generated image not shown after building jar-file

查看:192
本文介绍了构建jar文件后,JavaFX 2.2生成的图像未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的JavaFX应用程序中,我使用Apache生成barcode4j的条形码,将其保存为目录/ data / images /中的png图像,并将其嵌入到JavaFX WebView上显示的网页中。

In my JavaFX Application I generate a barcode with barcode4j by Apache, save it as png image in the directory /data/images/ and embed it in a web page which is shown on a JavaFX WebView.

生成条形码后,我使用以下Javascript代码将其嵌入网页:

After generating the barcode I embend it into the webpage using the following Javascript-Code:

path = "file:/" + path.replace(/\\/gi,"/");
var barcodeElement = document.getElementById("productBarcode");
barcodeElement.setAttribute("src", path );
barcodeElement.style.display = "inline-block";

我使用绝对路径C:\ path \ to \ java-program \ data \ myimage.png并从中构建文件URL。
在Eclipse中使用它没有任何问题。但是当我构建我的项目并从我的jar文件启动它时,图像不会显示。但问题不在于,路径不正确或生成图片不起作用,因此存在某种未找到错误。图像应该是白色的,周围有一个浅色边框。

I use the absolute path C:\path\to\java-program\data\myimage.png and build a file-URL from it. Using this in Eclipse works without any problems. But when I build my project and start it from my jar-file the image is not shown. But the problem is not, that the path is incorrect or that generating the picture does not work, so that there is some kind of "not found" error. The place where the image should be is just white with a light border around.

现在最奇怪的部分:如果你右键点击图像并选择打开新的窗口图像显示!

And now the strangest part: If you right click on the image and choose "open in new window" the image is shown!

有人对此有所了解吗?

非常感谢你提前!

推荐答案

我的理解是WebView不会让加载了一个协议的页面使用另一个协议访问文件。当您通过http://和禁止文件://加载时,这非常有意义。在这里,您正在通过jar:file:...加载,而webview只允许您访问jar:file:... resources(我刚试过,我可以从同一个jar中访问另一个jar文件中的图像文件,但不是来自外面!)。

My understanding is that the WebView won't let a page loaded with one protocol access files using another one. This makes perfect sense when you load through http://, and forbid file://. Here, you're loading through jar:file:..., and the webview will only let you access jar:file:... resources (I just tried, I can access an image from another jar file, from the same jar file, but not from outside!).

这听起来非常像是我的错误。

This sounds very much like a bug to me.

一个解决方法提到这里是使用data:URI(即直接在HTML文件中编码图像)。

One workaround mentioned here is to use "data:" URI (i.e. encode the image directly in the HTML file).

这篇关于构建jar文件后,JavaFX 2.2生成的图像未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆