1 Reply Latest reply: Nov 26, 2012 12:31 PM by 936814 RSS

    FXML application web start bug

    936814
      Hi all,
      running a JavaFx application as web start every time a FXML is loaded or a FXMLLoader.load(...) is called a
      HTTP GET request for javax.xml.stream.XMLInputFactory is made to the web server. This results
      in a HTTP 404 response

      This is the web server log
      [30/Oct/2012:09:47:12 -0400] "GET /applet/META-INF/services/javax.xml.stream.XMLInputFactory HTTP/1.1" 404 18869 "-" "Mozilla/4.0 (Windows 7 6.1) Java/1.7.0_09"

      If the same application (jnlp) is launched locally on the pc the problem does not occur.

      In a complex application that uses many FXML view this makes the application to run slowly till it freezes.

      I think this is a bug. Is there a work around?

      You can test this by running, as web start, this simple app:

      FxApp.java
      package fx.test;
      
      import javafx.application.Application;
      import javafx.fxml.FXMLLoader;
      import javafx.scene.Parent;
      import javafx.scene.Scene;
      import javafx.stage.Stage;
      
      public class FxApp extends Application {
        
        @Override
        public void start(Stage stage) throws Exception {
         Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml"));
          
          Scene scene = new Scene(root);
          
          stage.setScene(scene);
          stage.show();
        }
      
      
        public static void main(String[] args) {
          launch(args);
        }
      
      }
      Sample.java
      package fx.test;
      
      import java.io.IOException;
      import java.net.URL;
      import java.util.ArrayList;
      import java.util.List;
      import java.util.ResourceBundle;
      
      import javafx.event.ActionEvent;
      import javafx.fxml.FXML;
      import javafx.fxml.FXMLLoader;
      import javafx.fxml.Initializable;
      import javafx.scene.Node;
      import javafx.scene.control.TextField;
      import javafx.scene.layout.AnchorPane;
      
      public class Sample implements Initializable {
           int x = 0;
           int y = 0;
      
           @FXML
           AnchorPane pnlRoot;
           @FXML
           TextField txtItems;
      
           @Override
           public void initialize(URL arg0, ResourceBundle arg1) {
      
           }
      
           private void loadHello(int count) {
                List<Node> nodeList = new ArrayList<Node>();
                try {
      
                     for (int i = 0; i < count; i++) {
                          Node node = FXMLLoader.load(getClass().getResource("HelloWorld.fxml"));
                          node.setLayoutX(x);
                          node.setLayoutY(y);
                          // x += 10;
                          y += 50;
      
                          if (y > 600) {
                               y = 0;
                               x += 200;
                          }
      
                          nodeList.add(node);
                     }
      
                     this.pnlRoot.getChildren().addAll(nodeList);
      
                     nodeList.clear();
                } catch (IOException e) {
                     e.printStackTrace();
                }
           }
      
           @FXML
           private void btnTestClicked(ActionEvent event) {
                int c = Integer.parseInt(this.txtItems.getText());
      
                this.loadHello(c);
           }
      }
      HelloWorld.fxml
      <?xml version="1.0" encoding="UTF-8"?>
      
      <?import java.lang.*?>
      <?import javafx.scene.control.*?>
      <?import javafx.scene.layout.*?>
      <?import javafx.scene.layout.AnchorPane?>
      <?import javafx.scene.text.*?>
      
      <AnchorPane prefHeight="50.0" prefWidth="200.0" style="-fx-background-color: gray;" xmlns:fx="http://javafx.com/fxml">
        <!-- TODO Add Nodes -->
        <children>
          <Label alignment="CENTER" text="Hello World!" textFill="#fff500" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
            <font>
              <Font name="System Bold" size="30.0" />
            </font>
          </Label>
        </children>
      </AnchorPane>
      Sample.fxml
      <?xml version="1.0" encoding="UTF-8"?>
      
      <?import java.lang.*?>
      <?import javafx.scene.control.*?>
      <?import javafx.scene.layout.*?>
      <?import javafx.scene.layout.AnchorPane?>
      
      <AnchorPane fx:id="pnlRoot" prefHeight="600.0" prefWidth="800.0" xmlns:fx="http://javafx.com/fxml" fx:controller="fx.test.Sample">
        <!-- TODO Add Nodes -->
        <children>
          <HBox alignment="TOP_RIGHT" prefHeight="25.0" prefWidth="200.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
            <children>
              <TextField fx:id="txtItems" prefWidth="73.0" text="1" />
              <Button fx:id="btnTest" mnemonicParsing="false" onAction="#btnTestClicked" prefWidth="94.0" text="Test" />
            </children>
          </HBox>
        </children>
      </AnchorPane>