The Enterprise Side of JavaFX: The Missing Part

The JavaFX client template

Time’s up for the application client. The application client will use some JavaFX boilerplate code and a custom JNLP file we shall let NetBeans create for us. Therefore we shall create a temporary JavaFX project that we can steal stuff from. This project will not be added to our EAR project. We will only use this project as a nice template and later, we will delete the project.

In NetBeans, go to the menus and select File > New Project… > JavaFX > JavaFX FXML Application:

.

New JavaFX Template Part I

.

New JavaFX Template Part II

.

Please note a couple of things going on in this last screenshot. By default, NetBeans create some kind of a Default JavaFX Platform.. which I don’t use. As of Java SE 7 update 6, Oracle began distributing the JavaFX runtime libraries together with the Java SE downloads.

Also note that I create a MainFX application class. This will be the entry point for our JavaFX application. However, the ACC of GlassFish will invoke another Main class that kind of wraps our JavaFX application. Therefore I use different class names to separate the two classes from eachother. The ordinary Swing based Main class we shall soon create, will be named MainSwing. This class will hold the server side resources we need injected and I keep all JavaFX related stuff in a seperate class. You do whatever you like! I think you’ll get the picture soon enough.

As soon as you hit Finish, NetBeans will create some beautiful JavaFX code for you. However, we will also need that JNLP file I was talking about. Right-click your FXTemplate Project and select Properties. Select the Run tree node to your left. See the drop down list next to the label Configuration? Click on it and select Run as WebStart. Hit OK. Don’t worry about the screen dimensions, this shit can always be customized later.

Important!

Right click your FXTemplate project and select Clean and Build. This process will create the JNLP file for us. You cannot see the JNLP file in the projects tab, but you can see it in the Files tab > FXTemplate > dist.

.

10 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

Leave a Reply

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