Open Web Start and JavaFX

The public knowledge pool and discussion forum of the OWS community. Do not post confidential information here!
mhussainshah1
Posts: 3
Joined: 24 Aug 2021, 20:16

Open Web Start and JavaFX

Post by mhussainshah1 »

I am trying to run JavaFX on Open Web Start. I have followed all the steps mentioned in the

https://openwebstart.com/docs/FAQ.html# ... enwebstart
  • package the JavaFX application in a jar
  • gather platform (OS) specific jars from the OpenJFX libraries.
  • all jars must be signed and must have required security attributes in their manifests.
but I am getting error: java.lang.NoClassDefFoundError: javafx/application/Application.

I have attached log file .

The following is the code for JNLP file

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<jnlp spec="1.0+">

    <information>
        <title>ToggleButtonDemo Application</title>
        <vendor>Self</vendor>
        <offline-allowed />
    </information>

	<security>
		<sandbox/>
	</security>

	<resources>
		<java version="11+"/>
		<jar href="jars/ToggleButtonDemo.jar" main="true"/>
		<jar href="jars/javafx-controls-11.0.2-win.jar"/>
		<jar href="jars/javafx-graphics-11.0.2-win.jar"/>
		<jar href="jars/javafx-base-11.0.2-win.jar"/>
		<jar href="jars/javafx-fxml-11.0.2-win.jar"/>
	</resources>	    
	<application-desc main-class="ToggleButtonDemo"/>
</jnlp>

Attachments
2021-08-24_14_20_02.125-ows-stage2.log
Log File
(54.8 KiB) Downloaded 96 times
2021-08-24_14_20_02.125-ows-stage1.log
Log File
(18.18 KiB) Downloaded 101 times

Janak Mulani
Posts: 266
Joined: 24 Mar 2020, 13:37

Re: Open Web Start and JavaFX

Post by Janak Mulani »

Note: When running with Java 11+ the JavaFX Application is required to be launched via a launcher class:

Code: Select all

// Launcher for JavaFX application which is specified in the Jnlp file
public class HelloWorld11Launcher {
    public static void main(String[] args) {
        HelloWorld11.main(args);
    }
}

// JavaFX Application
public class HelloWorld11 extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    @Override
	public void start(Stage primaryStage) {
        ... // JavaFX code
    }
    ...
}

mhussainshah1
Posts: 3
Joined: 24 Aug 2021, 20:16

Re: Open Web Start and JavaFX

Post by mhussainshah1 »

Hi Janak,

Please find attached my simple JavaFX with OWS project.

I have created Launcher class as per your advice with JavaFx application class but I am still getting the same error.

The following is the sequence of my batch file (run.bat)
1) delete certificate, classes and jar files
2) gather platform (OS) specific jars from the OpenJFX libraries.
3) package the JavaFX application in a jar
4) sign all jars

Can you please reproduce the error to check what am I missing and share the output?

Thank you,

Muhammad Shah
Attachments
2021-08-25_13_59_58.226-ows-stage2.log
Error Log File
(44.14 KiB) Downloaded 65 times
This shows how to create certificate
This shows how to create certificate
Certificate.png (77.37 KiB) Viewed 1141 times
JDK 11
JDK 11
JDK.png (112 KiB) Viewed 1143 times
ClassNotFoundException
ClassNotFoundException
Error.png (92.73 KiB) Viewed 1143 times
JWS.zip
FX Project - click batch file run.bat to compile and execute JNLP - the password to create certificate file is test123
(7.32 KiB) Downloaded 79 times

Janak Mulani
Posts: 266
Joined: 24 Mar 2020, 13:37

Re: Open Web Start and JavaFX

Post by Janak Mulani »

I am able to run your app.

I compiled it with Java 8, created a jar, signed it. I chose OWS to use AdoptOpen Java 11 to run the ToggleButtonDemo app:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+" codebase="http://localhost:8080/jnlp">
    <information>
        <title>FX Toggle Button Oracle 11</title>
        <vendor>Karakun AG</vendor>
        <offline-allowed/>
    </information>
    <security>
        <all-permissions/>
    </security>
    <resources>
        <j2se version="11*" />
        <jar href="generated-jars/javafx-test.jar"/>
        <jar href="jars/s_javafx-controls-11.0.2-win.jar"/>
        <jar href="jars/s_javafx-graphics-11.0.2-win.jar"/>
        <jar href="jars/s_javafx-base-11.0.2-win.jar"/>
        <jar href="jars/s_javafx-fxml-11.0.2-win.jar"/>
    </resources>
    <application-desc main-class="com.karakun.ows.javafx_test.ToggleButtonDemoLauncher"/>
</jnlp> 

Code: Select all

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ToggleButton;
import javafx.scene.layout.FlowPane;
import javafx.stage.Stage;

public class ToggleButtonDemo extends Application {
    ToggleButton tBtnOnOff;
    Label response;

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        //Child Node
        response = new Label("Push the Button.");

        tBtnOnOff = new ToggleButton("On/Off");
        tBtnOnOff.setOnAction(event -> {
            if (tBtnOnOff.isSelected())
                response.setText("Button is on.");
            else
                response.setText("Button is off.");
        });

        //Parent
        FlowPane rootNode = new FlowPane(10, 10);
        rootNode.setAlignment(Pos.CENTER);
        rootNode.getChildren().addAll(tBtnOnOff, response);

        //Scene
        Scene scene = new Scene(rootNode, 220, 120);

        //Stage
        primaryStage.setScene(scene);
        primaryStage.setTitle("Demonstrate a Toggle Button");
        primaryStage.show();
    }
}

public class ToggleButtonDemoLauncher {
    public static void main(String[] args) {
        ToggleButtonDemo.main(args);
    }
}
[/code}

Janak Mulani
Posts: 266
Joined: 24 Mar 2020, 13:37

Re: Open Web Start and JavaFX

Post by Janak Mulani »

Differences I noted between your sample and mine :

Jnlp file:

Code: Select all

<security>
        <all-permissions/>
    </security>
Manifest of Jar file:

Code: Select all

Permissions: all-permissions
Codebase: *
Application-Library-Allowable-Codebase: *

Janak Mulani
Posts: 266
Joined: 24 Mar 2020, 13:37

Re: Open Web Start and JavaFX

Post by Janak Mulani »

I am able to run your app after building it using your run.bat and by deploying it in a server.

Running from command line like you do in the run.bat file where jnlp and jar files are local (not on server) I get the following.

Code: Select all

Caused by: java.lang.NoClassDefFoundError: javafx/application/Application. 
.

mhussainshah1
Posts: 3
Joined: 24 Aug 2021, 20:16

Re: Open Web Start and JavaFX

Post by mhussainshah1 »

Hi Janak

Can you please share your deployed code in the zip file? I would like to see how to put together files for tomcat.

We have a huge project on JavaFX. We are trying to move it from java 8 to 11.

Thank you,
Muhammad Shah

Janak Mulani
Posts: 266
Joined: 24 Mar 2020, 13:37

Re: Open Web Start and JavaFX

Post by Janak Mulani »

Hi Muhammad,

I do not know why your app jnlp is not running when started locally but runs when deployed on server.

However, I can start the same app (after I built it in my set up) both locally as well as by deploying on server.

I am attaching a zip file. It has jars and fxapp.jnlp. You can unzip and dbl-clk on the jnlp to start the apps (provided you have associated OWS's javaws with jnlp ext) or you can start jnlp from commandline. The Jnlp makes it evident how the app can be deployed on the server..

Since you have a huge project which is migrating from Java 8 to Java 11, I would recommend that you buy paid support https://openwebstart.com/#supportoptions . Please write to us on openwebstart@karakun.com for a quotation.

Thanks

Janak
Attachments
TestLocalJnlp.zip
(8.81 MiB) Downloaded 379 times

Post Reply