java 使用 JWS JNLP 为 JavaFX 应用程序创建桌面图标
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2080529/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Creating a desktop icon using JWS JNLP for a JavaFX app
提问by mikewilliamson
I am trying to get a custom destop icon to be displayed for my app but for some reason no matter what I do the same default java icon shows up. I have tried everything I can think of and gone and compared my jnlp file with others whose icons seem to work ok. According to everything I have read the following should work fine. But of course, it doesn't:
我正在尝试为我的应用程序显示一个自定义的 destop 图标,但出于某种原因,无论我做什么,都会显示相同的默认 Java 图标。我已经尝试了我能想到的所有方法,然后将我的 jnlp 文件与其他图标似乎工作正常的文件进行了比较。根据我阅读的所有内容,以下内容应该可以正常工作。但当然,它不会:
<information>
<title>MikesApp</title>
<vendor>Mike</vendor>
<homepage href="http://www.mikesapp.com/"/>
<description>Mikes App.</description>
<icon kind="shortcut" href="res/icon64x64.png" width="64" height="64"/>
<offline-allowed/>
<shortcut>
<desktop/>
</shortcut>
</information>
Any ideas would be greatly appreciated.
任何想法将不胜感激。
回答by Eric Wendelin
I would try the following, in order:
我会按顺序尝试以下操作:
- Create an icon of 32x32 in size and add it as an additional
<icon kind="shortcut".... The specsays that size is used for desktop icons. Use your 64x64 icon as the "default". For example, your new
<icon>elements would be:<icon href="res/icon64x64.png" width="64" height="64"/> <icon kind="shortcut" href="res/icon32x32.png" width="32" height="32"/> <icon kind="shortcut" href="res/icon64x64.png" width="64" height="64"/>Remember that your images are accessed relative to your
codebaseattribute in yourjnlpxml elementIf none of those work, you are welcome to compare your JNLP to one of mine that works.
- 创建一个 32x32 大小的图标并将其添加为附加
<icon kind="shortcut".... 该规范说,大小用于桌面图标。 使用您的 64x64 图标作为“默认”。例如,您的新
<icon>元素将是:<icon href="res/icon64x64.png" width="64" height="64"/> <icon kind="shortcut" href="res/icon32x32.png" width="32" height="32"/> <icon kind="shortcut" href="res/icon64x64.png" width="64" height="64"/>请记住,您的图像是相对于您
codebase的jnlpxml 元素中的属性访问的如果这些都不起作用,欢迎您将您的 JNLP 与我的JNLP 进行比较。
I realize that this JNLP stuff is kind of a pain. Hope one of these work for you.
我意识到这个 JNLP 的东西有点痛苦。希望其中之一对您有用。
回答by WindRider
I suppose the problem in your case is the missing CODEBASE attribute. See one working snippet:
我想你的问题是缺少 CODEBASE 属性。查看一个工作片段:
<?xml version="1.0"?>
<jnlp spec="1.5+"
codebase="http://www.sweethome3d.com/"
href="SweetHome3D.jnlp">
<information>
<title>Sweet Home 3D</title>
<vendor>eTeks</vendor>
<homepage href="http://www.sweethome3d.com/"/>
<description>Sweet Home 3D</description>
<description kind="short">Arrange the furniture of your house</description>
<icon href="SweetHome3DIcon.gif"/>
<icon kind="splash" href="SweetHome3DSplashScreen.jpg"/>
<offline-allowed/>
<shortcut online="false">
<desktop/>
<menu submenu="eTeks Sweet Home 3D"/>
</shortcut>
<association extensions="sh3d sh3l sh3f sh3t sh3p"
mime-type="application/SweetHome3D"/>
</information>
回答by David Martineau
We had the same problem. It worked fine initially then over time (a few Java updates?) it stopped working. When I got around to troubleshooting I discovered that even though javaws sends that it is gzip capable, our gzip response was not handled. I turned gzip off for these icons and it worked fine once again.
我们遇到了同样的问题。它最初运行良好,然后随着时间的推移(一些 Java 更新?)它停止工作。当我开始进行故障排除时,我发现即使 javaws 发送它支持 gzip,我们的 gzip 响应也没有被处理。我为这些图标关闭了 gzip,它再次正常工作。
回答by Matthew Hegarty
I don't have a specific answer I'm afraid, but Project MaiTaiis an open source application written in JavaFX, and that has a custom desktop icon.
恐怕我没有具体的答案,但Project MaiTai是一个用 JavaFX 编写的开源应用程序,它有一个自定义桌面图标。
If you haven't done so already, maybe checking the JNLP code for MaiTai would give you some pointers.
如果您还没有这样做,也许检查 MaiTai 的 JNLP 代码会给您一些提示。
回答by Simon Morris
There's an example of how to do this in the JavaFX in Action book, if you have access to that. You need to make sure the res/icon64x64.png file is actually downloadable from whatever site the app is hosted on, relative to the JNLP's location. Try loading it directly in a browser to ensure its available/valid.
如果您有权访问,JavaFX in Action 书中有一个示例说明如何执行此操作。您需要确保 res/icon64x64.png 文件实际上可以从托管应用程序的任何站点下载,相对于 JNLP 的位置。尝试直接在浏览器中加载它以确保其可用/有效。

