The Enterprise Side of JavaFX: The Missing Part

Build, deploy and run!

Pjuh, you made it here? Okay, right-click the SomeApp-ear project and select Clean and Build.

If you want Java Web Start to work, you cannot deploy the application through NetBeans (yes it must be a bug). Instead, make sure your GlassFish server is started (Tab Services > Tree node Servers > Right-click and select Start). Open a browser and go to the admin console at http://localhost:4848. Click on the Applications tree node to your left. Click button Deploy… > Choose File. Then select the newly built SomeApp-ear.ear file. On my machine, I found it here:

C:\Temp\SomeApp\SomeApp-ear\dist\SomeApp-ear.ear

Make sure Java Web Start is ticked and then hit OK. If you look in your GlassFish console (back in NetBeans), you’ll notice that GlassFish complains about not being able to find two classes:

javafx/application/Application
javafx/fxml/Initializable

Don’t worry too much about it. If we had packaged our JavaFX runtime library with our application client, GlassFish wouldn’t make this noise. However as you soon will see, the complaints has to the best of my knowledge no bearing.

In the list of deployed applications, click SomeApp-ear. In the Modules and Components table, click the Launch link. That should take you to a page with two URL:s. Copy-paste the URL of the first one into the browser’s address bar. If your GlassFish server works like mine, you have to change a phony computer name into localhost instead before you try to follow the link. Once you do follow the link, your browser downloads a JNLP file that you can double-click to execute your application client. First run might take some time!

When you’re prompted for username and password, enter user and password:

.

Swing user login

.

Did you notice that the login screen is made with Swing components? Click OK and you shall be thrown into a nice hardware accelerated JavaFX application. Click on the Click Me! button and if everything works, you should see the text “Remoting is awesum.” just beneath the button:

.

JavaFX Application

.

If (error)

If your application client failed to launch with a deceptive exception thrown..

java.io.FileNotFoundException:
http://localhost:8080/___JWSappclient/___system/___dyn/___system_s1as.jnlp

..then there is a fix for that too. Undeploy your application. Stop GlassFish. Delete your GlassFish disc caches. On my machine, I delete all I can find in these two folders (your domain might be called “domain1” instead of “gfdomain”):

C:\glassfish3\glassfish\domains\gfdomain\applications
C:\glassfish3\glassfish\domains\gfdomain\java-web-start

Happy JavaFX coding! And don’t forget to share your thoughts and whatever else you might find related to this tutorial.

11 thoughts on “The Enterprise Side of JavaFX: The Missing Part

  1. mauro

    hi your blog it is very very interessant.
    But how you resolve the problem with the call at remote ejb or application client on a glassfish behind a firewall ?

    For example i would download and use the appclient and the glassfish it is on a another macheine extenal at the internal net but on intenet .
    go at :
    https://www.java.net//forum/topic/glassfish/glassfish/ejb-remote-deployed-gf-31-behind-nat-unaccessible
    for view the problem .
    tanl you very much for your attention
    Mauro

    Reply
    1. martinandersson.com Post author

      I have no solution to your problem. Actually I haven’t read your URL:s, just looked over them briefly. However, all kinds of remoting is always troublesome if you’re behind a firewall. HTTP wired web services has no issue since they talk on port 80, almost always unblocked, and I believe this is the chief reason they have gained so much in popularity. So the moment a firewall gives you a headache, just expose the EJB as a web service. There is nothing stopping you from combining @WebService with @Stateless.

      Reply
  2. Pingback: JavaFX links of the week, July 22 // JavaFX News, Demos and Insight // FX Experience

  3. AFX

    Grymt martin! Keep it up!
    Nice kodat, och nu ska jag ta och kolla igenom resten av bloggen;) Man blir ju sugen på att börja koda själv fan. Verkar skitkul.

    Reply
  4. R

    Hi. Thanks for this blog post. It is really helpful. I’ve managed to run it inside the Netbeans. Unfortunately I’ve failed to do it outside the Netbeans. I used Glassfish appclient. I have the following errors……


    Exception in thread "main" java.lang.NoClassDefFoundError: javafx/application/Application
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at org.glassfish.appclient.client.acc.ACCClassLoader.findClass(ACCClassLoader.java:212)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at com.joy.azura.Sly.main(Sly.java:23)
    Caused by: java.lang.ClassNotFoundException: javafx.application.Application
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at org.glassfish.appclient.client.acc.ACCClassLoader.findClass(ACCClassLoader.java:212)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 13 more

    In line 14 (Sly.java:23) my code is

    javafx.application.Application.launch(SlyFX.class, args);

    I’m able to execute it inside the Netbeans. Thus, I think there is a way to do it outside of the Netbeans.

    Reply
    1. martinandersson.com Post author

      Could it be that the Application Client Container (ACC) cannot find your JavaFX runtime? And when you say “outside of NetBeans”, I hope you mean using Java Web Start? Please review page 8 and see if it helps. And be sure to upgrade your JDK installed if it is anywhere below 1.7.0_6.

      Reply
      1. R

        Thanks for your prompt reply. I was using the old next to obsolete method. “asadmin …get-client-stubs… appclient …” so you will have the lighter Glassfish on the client’s computer. Then to execute the Client side type “appclient.bat -jar MyApp-Client.jar” in command line. I have a fat client which needed to work offline. Fortunately requirements have changed. Now I have decided to switch to RESTful Web Service. That one has much better option. Thanks again.

        Reply
  5. Jeff

    Hi

    Is this still required/workable in Java/JavaFX 8, Glassfish 4.1 and netbeans 8.02?

    I quickly run through this tutorial in them and could not get it to work. I get a non specific security violation when the webstart finishes downloading and attempts to run it.

    Thanks!

    Reply
  6. Pingback: Java desktop links of the week, July 22 – Jonathan Giles

Leave a Reply

Your email address will not be published. Required fields are marked *