加载 JavaFX Applet 时启用调试日志

发布于 2024-09-17 18:58:16 字数 1174 浏览 15 评论 0原文

我的 JavaFX 应用程序在通过 JavaFX Eclipse 插件执行时正常工作。

但是当我尝试将它嵌入到我的网络项目中时,它没有正确渲染,过了一会儿,一个黑色矩形被加载到它的位置。

这是加载我的 JavaFX 应用程序的代码:

    <script src="http://dl.javafx.com/1.2/dtfx.js"></script>
    <script>
        javafx({
            codebase: "/applets/",
            archive: "HelloApplet.jar",
            draggable: false,
            width: 250,
            height: 80,
            code: "hello.HelloApplet",
            name: "HelloApplet"
       });
    </script>

这是我的 JavaFX 应用程序的代码:

    package hello;
    // some imports here
    // ...
    Stage {
      title: "My Applet"
      width: 250
      height: 80
      scene: Scene {
        content: Text {
            x: 10  y: 30
            font: Font { size: 24 }
            fill: Color.BLUE
            effect: DropShadow{ offsetX: 3 offsetY: 3}
            content: "Hello World!"
          } // Text
       } // Scene
    } // Stage

在我的 Web 项目中,我已将生成的 HelloApplet.jar 放入:

    src/main/webapp/applets/HelloApplet.jar

但无济于事,它仍然没有加载我在这里做错了什么?我错过了什么吗?

加载小程序时是否可以启用任何日志记录?

My JavaFX app is working when executed via the JavaFX Eclipse plugin.

But when I try to embed it into my web project, it is not being rendered properly and after a while a black rectangle is loaded in it's place.

Here is the code for loading my JavaFX Application:

    <script src="http://dl.javafx.com/1.2/dtfx.js"></script>
    <script>
        javafx({
            codebase: "/applets/",
            archive: "HelloApplet.jar",
            draggable: false,
            width: 250,
            height: 80,
            code: "hello.HelloApplet",
            name: "HelloApplet"
       });
    </script>

And here is the code for my JavaFX App:

    package hello;
    // some imports here
    // ...
    Stage {
      title: "My Applet"
      width: 250
      height: 80
      scene: Scene {
        content: Text {
            x: 10  y: 30
            font: Font { size: 24 }
            fill: Color.BLUE
            effect: DropShadow{ offsetX: 3 offsetY: 3}
            content: "Hello World!"
          } // Text
       } // Scene
    } // Stage

In my web project i have placed the generated HelloApplet.jar into:

    src/main/webapp/applets/HelloApplet.jar

but to no avail it is still not loading what am i doing wrong here? am i missing something?

Is it possible to enable any logging while loading the applet?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浅浅 2024-09-24 18:58:16

抱歉,我对 JavaFX 不够熟悉,无法帮助您解决此问题,但您可以查看控制台,以便通过在控制面板中启用它来查看堆栈跟踪和所有内容(如果您使用的是 Windows):

替代文本

I'm sorry, I'm not familiar enough with JavaFX to help you with that, but you can view the console so you can see the stack traces and everything by enabling it in the Control Panel (if you're using Windows):

alt text

风筝有风,海豚有海 2024-09-24 18:58:16

JavaFX 小程序使用新的 Java 插件架构,该架构使用 JNLP。要部署 JavaFX 小程序,您必须同时使用 html 文件和 jnlp 文件中的 javascript。当 IDE 生成 jnlp 和 html 文件时,它们会在这些文件中嵌入默认值,您必须确保这些值正确。在 Web 服务器上加载文件时,请确保以下事项:

  • 您的 javascript archive: 键与 jar 文件的名称匹配。
  • 您的 javascript code: 键指向小程序的主类
  • 您的 javascript jnlp_href: 键指向 jnlp 文件的正确位置
  • 您的 jnlp 文件需要引用的代码库代码所在的位置。

下面是一个示例:

javascript:

<script>
    javafx(
        {
              archive: "applet-demo.jar",
              width: 640,
              height: 75,
              code: "applet.demo.Main",
              name: "applet-demo",
              jnlp_href: "myapplet.jnlp"
        }
    );
</script>

myapplet.jnlp

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="http://javafxcookbook.s3.amazonaws.com/ch007/applet-demo" href="myapplet.jnlp">
    <information>
        <title>applet-demo</title>
        <vendor>Vladimir Vivien</vendor>
        <homepage href="http://javafxcookbook.s3.amazonaws.com/ch007/applet-demo"/>
        <description>applet-demo</description>
        <offline-allowed/>
        <shortcut>
            <desktop/>
        </shortcut>
    </information>
    <resources>
        <j2se version="1.5+"/>
        <extension name="JavaFX Runtime" href="http://dl.javafx.com/1.2/javafx-rt.jnlp"/>
        <jar href="applet-demo.jar" main="true"/>
    </resources>
    <applet-desc name="applet-demo" main-class="com.sun.javafx.runtime.adapter.Applet" width="640" height="75">
        <param name="MainJavaFXScript" value="applet.demo.Main">
    </applet-desc>
    <update check="background">
</jnlp>

JavaFX applet uses the new Java-Plugin architecture which uses JNLP. To deploy JavaFX applets you must use both the javascript in html file and the jnlp file. When IDE's generate the jnlp and the html file, they embed default values in those files that you must ensure are correct. Make sure of the following when you load your files on the web server:

  • Your javascript archive: key matches the name of the jar file.
  • Your javascript code: key points to the main class of the applet
  • Your javascript jnlp_href: key points to the proper location of the jnlp file
  • Your jnlp file needs to the codebase referring to the location where the code resides.

Below is a sample:

javascript:

<script>
    javafx(
        {
              archive: "applet-demo.jar",
              width: 640,
              height: 75,
              code: "applet.demo.Main",
              name: "applet-demo",
              jnlp_href: "myapplet.jnlp"
        }
    );
</script>

myapplet.jnlp

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="http://javafxcookbook.s3.amazonaws.com/ch007/applet-demo" href="myapplet.jnlp">
    <information>
        <title>applet-demo</title>
        <vendor>Vladimir Vivien</vendor>
        <homepage href="http://javafxcookbook.s3.amazonaws.com/ch007/applet-demo"/>
        <description>applet-demo</description>
        <offline-allowed/>
        <shortcut>
            <desktop/>
        </shortcut>
    </information>
    <resources>
        <j2se version="1.5+"/>
        <extension name="JavaFX Runtime" href="http://dl.javafx.com/1.2/javafx-rt.jnlp"/>
        <jar href="applet-demo.jar" main="true"/>
    </resources>
    <applet-desc name="applet-demo" main-class="com.sun.javafx.runtime.adapter.Applet" width="640" height="75">
        <param name="MainJavaFXScript" value="applet.demo.Main">
    </applet-desc>
    <update check="background">
</jnlp>
当爱已成负担 2024-09-24 18:58:16

您应该检查JNLP 文件中codebase 的方向,其中应包含.jar 的正确路径。

例如,如果我的 .jar 位于 C:\Users\rodrigo\Documents\NetBeansProjects\JavaFXJavaScript\dist,那么我的 JNLP 应该是 http:// /localhost:8082/servlet/org.netbeans.modules.javafx.project.JnlpDownloadServlet/C%3A/Users/rodrigo/Documents/NetBeansProjects/JavaFXJavaScript/dist/

You should check the direction of codebase in file JNLP, which should contain the correct path of your .jar.

For example, if I have my .jar at C:\Users\rodrigo\Documents\NetBeansProjects\JavaFXJavaScript\dist, then my JNLP should be http://localhost:8082/servlet/org.netbeans.modules.javafx.project.JnlpDownloadServlet/C%3A/Users/rodrigo/Documents/NetBeansProjects/JavaFXJavaScript/dist/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文