wood burning stoves 2.0*
The moose likes JavaFX and the fly likes How can I include a JavaFX 2.0 application into a HTML page? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JavaFX
Bookmark "How can I include a JavaFX 2.0 application into a HTML page?" Watch "How can I include a JavaFX 2.0 application into a HTML page?" New topic
Author

How can I include a JavaFX 2.0 application into a HTML page?

Gerhard Heil
Greenhorn

Joined: Dec 19, 2011
Posts: 6
Hello all,

I am a JavaFx newbie (and I am not a HTML or script expert). I am implementing my first JavaFx application (JavaFx 2.0) and I succeeded to get it startable out of NetBeans (by Run Main project) and, without NetBeans, by click on the jar file. That works fine.

JavaFx feature description says that a JavaFx application is startable
1) standalone
2) within a browser
3) via WebStart

So as next step I want to get it started within a browser; as I understood the feature description, I would have to include a JavaScript tag (or anything else) into a HTML page, so the JavaFx application would be embedded within the browser window, looking similar to active components like JSP, JSF etc. Is that correct? From Oracle JavaFx forum, I got the hint to use NetBeans, that would generate all package files.

In fact, NetBeans generates a launch.jnlp file and a launch.html file referring this jnlp (for the WebStart), but it does not generate a HTML file, and I have no idea what to write.

I also tried to insert a tag <fx:deploy ...> within build-impl.xml, with definition of xmlns:fx, but that is not even compilable (Problem: failed to create task or type javafx:com.sun.javafx.tools.ant:deploy; Cause: The name is undefined).

I also read the Oracle deployment tutorial, but that describes JavaFx 1.3 and that is not compatible to JavaFx 2.0 (or I followed it somehow incorrect). So what is to be done to get the JafaFx 2.0 application started within the browser? What do I have to write in a HTML page? And what do I have to specify in NetBeans project properties or in the build.xml or build-inpl.xml (if that requires any certain settings)?

The tools I currently use are:
NetBeans 7.1 RC1
JavaFx_2.0_SDK
Java JRE 7

Thank you very much for any support.

Best regards
Gerhard
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Gerhard Heil wrote:I also read the Oracle deployment tutorial, but that describes JavaFx 1.3 and that is not compatible to JavaFx 2.0

Have you gone through the Packaging and Deployment trail linked from Oracle's JavaFX 2.0 Documentation page?
Gerhard Heil
Greenhorn

Joined: Dec 19, 2011
Posts: 6
Hello,

obviously the post that I sent yesterday, was not stored in the forum database. Here once more:

The deployment chapter in the mentioned document describes the deployment of JavaFx Script, not JavaFx 2.0 (at least I understood so and a post in the Oracle JavaFx forum stated that also). Maybe I need only to change a little detail from that description.

Nevertheless I tried to follow that description and wrote a task <fx:deploy> in build-impl.xml (together with defining fx namespace), but NetBeans rejected this, as the name fx:deploy is unknown!

Besides that I got this hint in that forum: But easiest way would be install Netbeans 7.1 and use JavaFX project there. It will use ant task behind the scene to generate all package files. Indeed, NetBeans generates a jnlp file and a html file with a Launch button referring the jnlp. Launching via this jnlp throws an exception, but that is another discussion. If it would work, it would open a new window for the launched application.

In this thread I am asking about starting the application inside the browser (as an applet if that is the correct term). I imagine it would (from users point of view) look and behave like a HTML page containing JSF or Facelets components. I assume for that I would need a HTML file containing something like or similar to
<script>
function deployIt() { ...
}
</script>

But I did not find out what to write in the HTML file. Do I need anything else in the application coding (for example setting an id that would be referred in the HTML tag), in the build.xml or build-impl.xml or somewhere else? Is there any detailed and working description how to implement the promised JavaFx feature of starting the application inside a browser?

Thank you for your help.

Best regards
Gerhard
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

The deployment chapter in the mentioned document describes the deployment of JavaFx Script, not JavaFx 2.0

I don't see anything related to JavaFX Script (1.x) in the tutorial trail I referred you to. Please provide a link to the page that led you to believe that.

a post in the Oracle JavaFx forum stated that also

Please provide a link so that I can correct the misunderstanding ... provided you're not referring to an old post containing information that was possibly correct at the time it was posted.
Gerhard Heil
Greenhorn

Joined: Dec 19, 2011
Posts: 6
Hello Darryl,

some weeks ago I found the Oracle tutorial http://docs.oracle.com/javafx/2.0/deployment/deployment_toolkit.htm#BABJHEJA what explains:
Creating a dtjava.App Object:
var app = new dtjava.App( ... );

I had seen that syntax in some JavaFx 1.x descriptions, but not in JavaFx 2.0. And I did not find any definition of dtjava.App. So I am not sure whether this dtjava.App object is to be created in the JavaFx code or in the HTML page.

I had posted the same query earlier in Oracle JavaFx forum (https://forums.oracle.com/forums/thread.jspa?messageID=10008333) and there I wrote my assumption of Javafx script, and got the confirmation:
What you are looking at in the guide is Deployment Toolkit and it uses javascript syntax, not javafx. ...
Start with getting started section (http://docs.oracle.com/javafx/2.0/deployment/deploy_quick_start.htm#BABJCFHC) and use javafxpackager
(or better ant task) to package app.
But easiest way would be install Netbeans 7.1 and use JavaFX project there. It will use ant task behind the scene to generate all package files.

I tried following the getting started section; this describes an ant task <fx:deploy ...>. As I use NetBeans, I included the fx:deploy task in my build-impl.xml, but NetBeans rejects it as the name fx:deploy is unknown (though I have defined the fx namespace). Maybe I have a syntax error somewhere or need to define the namespace somewhere else or whatever, so perhaps I could succeed the fx:deploy after any correction. Or maybe NetBeans does it easier, if I only find out what to enter in the project properties.

But once I have run the fx:deploy task successfully or once NetBeans has generated all required files, I assume I need any way to invoke the JavaFx application from the browser. The browser loads a HTML page, and how is the JavaFx application referred there? The examples 5-3, 5-4 and 5-5 in http://docs.oracle.com/javafx/2.0/deployment/deployment_toolkit.htm#BABJHEJA describe inserting a <script> tag in a HTML page. I assume the syntax of that tag might be different for a JavaFx 2.0 application, but the concept of inserting a <script> tag (or perhaps some other tag) in the HTML file looks ok. What is the correct way of referring the application? And what do I have to do to get the application loadable?

Thanky for your support. I wish you a merry Christmas and a happy new year.
Best regards
Gerhard
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Gerhard Heil wrote:The deployment chapter in the mentioned document describes the deployment of JavaFx Script, not JavaFx 2.0

Gerhard Heil wrote: What you are looking at in the guide is Deployment Toolkit and it uses javascript syntax, not javafx.


JavaScript is not JavaFX script.
Gerhard Heil
Greenhorn

Joined: Dec 19, 2011
Posts: 6
Hello,

ok, I really read JavaFx script, where Igor wrote Javascript.

So Javascript is compatible with JavaFx 2.0, and to invoke my application inside a browser, I need a HTML page with a Javascript tag, right?

If so, I feel I am one step further. But I still don´t see exactly what to do. Strictly follow the description "Deployment in the browser"? Do I need the dtjava.App object? Where should I create that? In the javascritp tag in the HTML page or in the JavaFx application code? In which class / method?

Do I need a working jnlp file for starting the application inside the browser? All the examples in chapter 5.3.1 in that description refer a jnlp file.

Best regards
Gerhard
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Gerhard Heil wrote:So Javascript is compatible with JavaFx 2.0


JavaScript is not Java (or, as one of our members was fond of saying, the two are alike as ham and hamster).

  • JavaScript is not Java.
  • JavaFX 1.x is not Java, but can make use of Java classes.
  • JavaFX 2.0 is a Java API.
  • Gerhard Heil
    Greenhorn

    Joined: Dec 19, 2011
    Posts: 6
    I still don´t see what to do.

    Should I strictly follow the description "Deployment in the browser"? Do I need the dtjava.App object? Where should I create that? In the javascritp tag in the HTML page or in the JavaFx application code? In which class / method?

    Do I need a working jnlp file for starting the application inside the browser? All the examples in chapter 5.3.1 in that description refer a jnlp file. NetBeans creates a jnlp file, but starting via WebStart does also not work.

    Best regards
    Gerhard
    Eric Love
    Greenhorn

    Joined: Feb 09, 2012
    Posts: 1
    The answer is yes. Follow the information contain in the "Deployment in browser" documentation. The dtjava.App object are referencing the dtjava.js JavaScript file (http://java.com/js/dtjava.js).
    John Damien Smith
    Ranch Hand

    Joined: Jan 26, 2012
    Posts: 130
        
        9
    starting via WebStart does also not work

    WebStart is currently (as of 2.0.2) and (2.1 early access build 12) is only supported on Windows platforms on certain browsers.
    WebStart for JavaFX for Windows XP will only work with (2.1 early access build 12) and later due to a WebStart deployment system bug: http://javafx-jira.kenai.com/browse/RT-18572
    Other than that (e.g. if you are using Windows 7 or a later version of JavaFX which supports your target operating system and browser), then WebStart should launch correctly configured applications from a webpage fine.
    Frank Frankss
    Greenhorn

    Joined: Sep 18, 2012
    Posts: 3
    Please where can I download the JavaFX runtime for version 1.3. And secondly, after writing a JavaFX application, I am not able to package it for deployment. I use NetBean 6.9 Beta and when I click Build Project, it say it has finished build. When i locate the jar file in the dist folder in order to run it, it gives a Java Exception.............(reported by the JVM). Please how can i solve this problem and how can I also package a program to become self-contained application? Please help me
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: How can I include a JavaFX 2.0 application into a HTML page?
     
    Similar Threads
    deploying JNLP in Jetty web server of jboss.
    about struts
    interpreting javascript with RESTful servlet
    dynamic Checkboxe value retrieval
    With JavaFX can develop both web and desktop Apps