3 Replies Latest reply: Feb 13, 2012 11:50 AM by 817264 RSS

    How to embed JavaFX 2.0 application with jsp (to deploy it on server)

      Hi All,

      i am very new to JavaFX 2.0, i have downloaded the javaFX sdk and runtime and created standalone projects using eclipse IDE.

      now i want to deploy these stand alone application in jboss server to give demo to my client, i tried so many ways but failed to deploy the application on server.

      can any body tell me the steps how can i embed and deploy the javaFX 2.0 application on server.

      the below one is my javaFX code.

      1. import javafx.application.Application;
      2. import javafx.geometry.HPos;
      3. import javafx.geometry.Insets;
      4. import javafx.scene.Group;
      5. import javafx.scene.Scene;
      6. import javafx.scene.control.Button;
      7. import javafx.scene.control.Label;
      8. import javafx.scene.control.TextField;
      9. import javafx.scene.layout.GridPane;
      10. import javafx.scene.paint.Color;
      11. import javafx.stage.Stage;
      13. public class AddingControlsToLayout extends Application { 
      15. public static void main(String args[]){ 
      16. launch(args);
      17. }
      19. @SuppressWarnings("static-access")
      20. @Override
      21. public void start(Stage primaryStage) throws Exception { 
      22. primaryStage.setTitle("Adding Controls to Layout.");
      23. Group group = new Group();
      24. Scene scene = new Scene(group,350,300,Color.WHITE);
      26. GridPane gridPane = new GridPane();
      27. gridPane.setPadding(new Insets(5));
      28. gridPane.setHgap(5);
      29. gridPane.setVgap(5);
      31. Label fNameLabel = new Label("First Name");
      32. TextField fNameTF = new TextField();
      34. Label lNameLabel = new Label("Last Name");
      35. TextField lNameTF = new TextField();
      37. Button saveButton = new Button("Submit");
      39. gridPane.setHalignment(fNameLabel, HPos.RIGHT);
      40. gridPane.add(fNameLabel, 0, 0);
      42. gridPane.setHalignment(lNameLabel, HPos.RIGHT);
      43. gridPane.add(lNameLabel, 0, 1);
      45. gridPane.setHalignment(fNameTF, HPos.LEFT);
      46. gridPane.add(fNameTF, 1, 0);
      48. gridPane.setHalignment(lNameTF, HPos.LEFT);
      49. gridPane.add(lNameTF, 1, 1);
      51. gridPane.setHalignment(saveButton, HPos.RIGHT);
      52. gridPane.add(saveButton, 1, 2);
      54. group.getChildren().add(gridPane);
      56. primaryStage.setScene(scene);
      57. primaryStage.show();
      59. }
      60. }

      i have tried to embed JavaFX application with applet code but it has thrown exception like its not an applet and can't be type cast some thing.

      i dont know JNLP much but i have tried with sample code which are available on web but its giving jnlp error

      my jnlp and jsp code is here:

      1. <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      2. pageEncoding="ISO-8859-1"%>
      3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
      4. <html>
      5. <head>
      6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      7. <title>RippleEffect</title>
      8. </head>
      9. <body>
      10. <h1>Adding Controls to Layout q1 q</h1>
      11. <script src="dtfx.js"></script>
      12. <script>
      13. javafx(
      14. { 
      15. archive: "WorkBook1.jar,",
      16. draggable: true,
      17. width: 200,
      18. height: 200,
      19. code: "webapplication.AddingControlsToLayout",
      20. name: "Foo",
      21. loading_image_url: "http://dl.javafx.com/javafx-loading-100x100.gif",
      22. loading_image_height: "120",
      23. loading_image_width: "80"
      24. }
      25. );
      27. </script>
      28. </body>
      29. </html>
      31. and jnlp code is here:
      33. <?xml version="1.0" encoding="utf-8"?>
      34. <jnlp spec="1.0+" codebase="http://localhost:8080/Demo/" href="Test.jnlp">
      35. <information>
      36. <title>Jnlp Testing</title>
      37. <vendor>YONG MOOK KIM</vendor>
      38. <homepage href="http://localhost:8080/Demo/hello.jsp" />
      39. <description>Testing Testing</description>
      40. </information>
      41. <security>
      42. <all-permissions/>
      43. </security>
      44. <resources>
      45. <j2se version="1.7+" />
      46. <extension name="JavaFX Runtime" href="http://dl.javafx.com/1.3/javafx-rt.jnlp"/>
      47. <jar href="WorkBook1.jar" />
      48. </resources>
      49. <application-desc main-class="webapplication.AddingControlsToLayout" />
      50. </jnlp>

      can anybody please give me some sample code or tell me what is the problem in my code.

      Thanks in Advance

      Edited by: maddy807 on Feb 9, 2012 1:33 AM
        • 1. Re: How to embed JavaFX 2.0 application with jsp (to deploy it on server)
          For your simple example you can just use a static html file rather than a jsp.
          Start by getting a static html file generated by the JavaFX deployment scripts (javafxpackager or the JavaFX ant tasks) working. The easiest way to get something up and running when first getting into JavaFX is just to use NetBeans 7.1+ and click the NetBeans packaging options to generate the jar, jnlp and html files you need. Once you have done that, the tasks to get it working when served by a server are (assuming you call your application RippleEffect):
          1. Download and install a copy of Tomcat (http://tomcat.apache.org/download-70.cgi)
          2. Copy the jar, jnlp and html file into tomcat's webapps/ROOT directory.
          3. Start tomcat.
          4. Access your application via http://localhost:8080/RippleEffect.html
          The applet will start automatically and you can click on the link to launch the application via WebStart.
          Note that (as of JavaFX 2.0.2) applet and webstart launching of JavaFX applications only works on the Windows platform.
          Once you have your application being hosted inside a static html page, converting that page to a jsp should be trivial if you are already familar with jsp technology.
          See the sticky thread at the top of the forums for info on posting formatted code.
          • 2. Re: How to embed JavaFX 2.0 application with jsp (to deploy it on server)
            Thank you very much John,

            i have changed jsp page to html page and instead of dtfx.js i am using dtjava.js
            the below one is my html page

            but i am getting below exception.

            ExitException[ 3]JNLPException[category: Launch File Error : Exception: java.lang.Exception: JNLP not an applet, nor a JavaFX application : LaunchDesc:
            <jnlp spec="1.0+" xmlns:jfx="http://javafx.com" codebase="http://localhost:8080/TestJnlpProject/" href="Test.jnlp">
                <title>Jnlp Testing</title>
                <vendor>YONG MOOK KIM</vendor>
                <homepage href="http://localhost:8080/TestJnlpProject/hello.html"/>
                <description>Testing Testing</description>
                <j2se version="1.7+"/>
                <jar href="http://localhost:8080/TestJnlpProject/TestJnlp.jar"/>
                <jar href="http://localhost:8080/TestJnlpProject/jfxrt.jar"/>
              <application-desc main-class="webapplication.AddingControlsToLayout"/>
            </jnlp> ]
                 at sun.plugin2.applet.JNLP2Manager.loadJarFiles(Unknown Source)
                 at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
                 at java.lang.Thread.run(Unknown Source)

            my html code is

            <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
            <script type="text/javascript" src="dtjava.js"></script>
            function deployIt() {
            {         id: "myApp",
            url: "Test.jnlp",
            width: 300,
            height: 200,
            placeholder: "place"
            { jvm: "1.6.0+",
            javafx: "2.0+",
            jvmargs: "-Dsun.some=xx -Xmx1024m" },
                 //onGetSplash: function(app, mismatchEvent) {alert(mismatchEvent.javafxStatus());}

                      id: "myApp",
            url: "Test.jnlp",
            width: 300,
            height: 200,
            placeholder: "place"
            { jvm: "1.6.0+",
            javafx: "2.0+",
            jvmargs: "-Dsun.some=xx -Xmx1024m" },

            <h1>Adding Controls to Layout</h1>
            <div id="place"></div>

            if i use dtjava.launch the application is launching but i need to embed in browser so i used dtjava.embed but its giving the above error.

            can you please help me out from this problem.

            • 3. Re: How to embed JavaFX 2.0 application with jsp (to deploy it on server)
              This JNLP file WAS NOT generated by JavaFX tools.

              With JavaFX 2.0 you do not need to edit JNLP file yourself if you use javafx tools.
              If you are not feeling expert in the JNLP or are not facing blocking issue then do not try to edit and manually craft them.

              Please use javafxpackager or ant tasks

              It looks like you are trying to reuse JNLP for javafx 1.3. It will not work with JavaFX 2.0 application.