views:

33

answers:

3

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"&gt;&lt;/script&gt;
    <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?

+2  A: 

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

The Alchemist
There is this tool called JaNeLA. It really gives details on what is really happening at the back and gives suggestions. you can visit them @ http://pscode.org/janela/
Joopiter
A: 

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/

rsa
+1  A: 

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"/&gt;
        <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"/&gt;
        <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>
vladimir.vivien