简体   繁体   English

通过浏览器为简单HelloWorld应用程序运行JavaFX

[英]Getting JavaFX to run via Browser for Simple HelloWorld app

I tried following various tutorials for getting a JavaFX hello world app running in a browser. 我尝试遵循各种教程来使JavaFX hello world应用程序在浏览器中运行。 I can't believe it's that hard, so I'm looking for any insight into what I may have done wrong. 我真不敢那么难,所以我正在寻找对我做错了什么的任何见解。 Some things I've tried and resolved (to rule out the obvious): 我已经尝试并解决的一些事情(排除显而易见的事情):

  • Had to download 32-bit JRE for the browsers and ensure they were using that 必须为浏览器下载32位JRE,并确保它们正在使用该浏览器
  • Thus using the latest JRE (7u21); 因此使用最新的JRE(7u21); running on Win 7 64-bit 在Win 7 64位上运行
  • Checked Windows Control Panel -> Programs -> Java to verify the JRE being used 检查Windows控制面板->程序-> Java以验证正在使用的JRE
  • Signed the JAR file 签署了JAR文件
  • Tried running from local file, found that drive letters weren't recognized, so moved to running via Tomcat 6 尝试从本地文件运行,发现无法识别驱动器盘符,因此转为通过Tomcat 6运行
  • Tried various changes to the codebase and url hrefs, but I believe those are correct. 尝试对代码库和url hrefs进行各种更改,但我相信这些更改是正确的。
  • Tried in both IE 10 and Chrome 在IE 10和Chrome中都尝试过

What I ended up with was that loading the .html (which references the jnlp using the JavaFX default javascript) would spin for a while then fail. 我最终得到的结果是,加载.html(使用JavaFX默认JavaScript引用jnlp)会旋转一段时间,然后失败。 If I try to load the .jnlp file directly, I get an exception: 如果我尝试直接加载.jnlp文件,则会出现异常:

ClassNotFoundException: javafx.application.Application

I verified that the jfxrt.jar is in the lib folder of the JRE that the browser is using. 我验证了jfxrt.jar在浏览器正在使用的JRE的lib文件夹中。

Any insight/suggestions as to what I may be missing at this point? 关于我此时可能会缺少什么的任何见解/建议? Seems like it must be something obvious/basic at this point, but I'm not seeing it. 在这一点上看来它一定是显而易见的/基本的,但是我没有看到它。 Thanks. 谢谢。

Just to follow-up, I went ahead and used javafxpackager. 为了跟进,我继续使用javafxpackager。 That produced a web page that would load the JavaFX application in Chrome. 那产生了一个网页,该网页将在Chrome中加载JavaFX应用程序。 However, it still doesn't work in IE. 但是,它仍然无法在IE中使用。 I'm going to write that off as an IE but since it works in Chrome. 我将其作为IE进行注销,但由于它可以在Chrome中使用。 What I did learn by looking at the results, though, is there are several things javafxpackager does, and the results of that are not exactly what's described in most of the manual tutorials/examples. 不过,我通过查看结果了解到的是javafxpackager有几项工作,并且这些结果与大多数手动教程/示例中所描述的都不完全相同。 Minor differences, but apparently they matter. 细微的差异,但显然很重要。

It sounds as you don't have the JavaFX starter classes in your JAR (usually done by the Ant script) and don't have the correct JavaFX Manifest entries. 听起来这是因为您的JAR中没有JavaFX入门类(通常由Ant脚本完成)并且没有正确的JavaFX清单条目。

It should not be needed to add the jfxrt.jar as a resource to your JNLP file and you shouldn't have to sign it. 不需要将jfxrt.jar作为资源添加到JNLP文件中,并且您不必对其进行签名。

Please show your Manifest file. 请显示您的清单文件。

The Manifest file should contain at least the following JavaFX entries: 清单文件应至少包含以下JavaFX条目:

JavaFX-Version: 2.2
JavaFX-Application-Class: yourPackage.YourApplication
Main-Class: com/javafx/main/Main

The JAR should contain the classes of the com.javafx.main package provided by the ant-javafx.jar (see /resources/classes in that Jar). JAR应该包含ant-javafx.jar提供的com.javafx.main包的类(请参见该Jar中的/ resources / classes)。 The ant-javafx.jar is provided by the JDK. ant-javafx.jar由JDK提供。

I was able to mostly resolve my problem. 我基本上可以解决我的问题。 I'm using Eclipse, not NetBeans, so doing a lot manually. 我使用的是Eclipse,而不是NetBeans,因此需要手动进行很多操作。 The basic problem was that I had to include the jfxrt.jar as a resource in the jnlp file (and that jar also had to be signed). 基本问题是我必须将jfxrt.jar作为资源包含在jnlp文件中(并且该jar也必须进行签名)。

My app now runs if I access the jnlp directly, though it still doesn't work via html page. 如果我直接访问jnlp,我的应用程序现在可以运行,尽管它仍然无法通过html页面运行。 I'll post an update if/when I figure that part out. 如果/当我弄清楚那一部分时,我会发布更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM