title: JavaFX : Maven project cannot find css files, without Maven css files are found
body: <p>Sorry for the weird title, didn't knew what exactly to write. I am working on a JavaFX application with Java8. For this purpose, I have the <code>javafx-maven-plugin</code> from <code>com.zenjava</code>. I have a simple code for testing, where there is a Main class, and one css page for styling. I have the same project without maven, and it works fine. But with Maven I am unable to get it running. I get an NPE for the CSS file-. I have tried multiple options already. Any help would be nice. Thank you.</p>
  
  <p>Error log :</p>
  
  <pre><code>Exception in Application start method
  Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
      at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
      at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: java.lang.NullPointerException
      at View.Main.start(Main.java:110)
      at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
      at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
      at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
      at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
      at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
      at com.sun.glass.ui.gtk.GtkApplication.lambda$null$49(GtkApplication.java:139)
      ... 1 more
  </code></pre>
  
  <p>POM.xml :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;MavenFX&lt;/groupId&gt;
      &lt;artifactId&gt;MavenFX&lt;/artifactId&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
      &lt;properties&gt;
          &lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
          &lt;maven.compiler.target&gt;1.8&lt;/maven.compiler.target&gt;
      &lt;/properties&gt;
      &lt;dependencies&gt;
  
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
        &lt;plugin&gt;
  
            &lt;groupId&gt;com.zenjava&lt;/groupId&gt;
            &lt;artifactId&gt;javafx-maven-plugin&lt;/artifactId&gt;
            &lt;version&gt;8.2.0&lt;/version&gt;
            &lt;configuration&gt;
                &lt;mainClass&gt;View.Main&lt;/mainClass&gt;
            &lt;/configuration&gt;
        &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>Main class :</p>
  
  <pre><code>package View;
  
  import javafx.application.Application;
  import javafx.geometry.Insets;
  import javafx.scene.Scene;
  import javafx.scene.control.Button;
  import javafx.scene.control.Label;
  import javafx.scene.control.PasswordField;
  import javafx.scene.control.TextField;
  import javafx.scene.effect.DropShadow;
  import javafx.scene.effect.Reflection;
  import javafx.scene.layout.BorderPane;
  import javafx.scene.layout.GridPane;
  import javafx.scene.layout.HBox;
  import javafx.scene.paint.Color;
  import javafx.scene.text.Font;
  import javafx.scene.text.FontWeight;
  import javafx.scene.text.Text;
  import javafx.stage.Stage;
  
  public class Main extends Application {
  
  
      String user = "JavaFX2";
      String pw = "password";
      String checkUser, checkPw;
  
  
      @Override
      public void start(Stage primaryStage) throws Exception{
          primaryStage.setTitle("Test Login");
  
          BorderPane bp = new BorderPane();
          bp.setPadding(new Insets(10,50,50,50));
  
          //Adding HBox
          HBox hb = new HBox();
          hb.setPadding(new Insets(20,20,20,30));
  
          //Adding GridPane
          GridPane gridPane = new GridPane();
          gridPane.setPadding(new Insets(20,20,20,20));
          gridPane.setHgap(5);
          gridPane.setVgap(5);
  
          //Implementing Nodes for GridPane
          Label lblUserName = new Label("Username");
          final TextField txtUserName = new TextField();
          Label lblPassword = new Label("Password");
          final PasswordField pf = new PasswordField();
          Button btnLogin = new Button("Login");
          final Label lblMessage = new Label();
  
          //Adding Nodes to GridPane layout
          gridPane.add(lblUserName, 0, 0);
          gridPane.add(txtUserName, 1, 0);
          gridPane.add(lblPassword, 0, 1);
          gridPane.add(pf, 1, 1);
          gridPane.add(btnLogin, 2, 1);
          gridPane.add(lblMessage, 1, 2);
  
  
          //Reflection for gridPane
          Reflection r = new Reflection();
          r.setFraction(0.7f);
          gridPane.setEffect(r);
  
          //DropShadow effect
          DropShadow dropShadow = new DropShadow();
          dropShadow.setOffsetX(5);
          dropShadow.setOffsetY(5);
  
          //Adding text and DropShadow effect to it
          Text text = new Text("Test Login");
          text.setFont(Font.font("Courier New", FontWeight.BOLD, 28));
          text.setEffect(dropShadow);
  
          //Adding text to HBox
          hb.getChildren().add(text);
  
          //Add ID's to Nodes
          bp.setId("bp");
          gridPane.setId("root");
          btnLogin.setId("btnLogin");
          text.setId("text");
  
          //Action for btnLogin
          btnLogin.setOnAction(event -&gt; {
              checkUser = txtUserName.getText();
              checkPw = pf.getText();
              if(checkUser.equals(user) &amp;&amp; checkPw.equals(pw)){
                  lblMessage.setText("Congratulations!");
                  lblMessage.setTextFill(Color.GREEN);
              }
              else{
                  lblMessage.setText("Incorrect user or pw.");
                  lblMessage.setTextFill(Color.RED);
              }
              txtUserName.setText("");
              pf.setText("");
          });
  
          //Add HBox and GridPane layout to BorderPane Layout
          bp.setTop(hb);
          bp.setCenter(gridPane);
  
          //Adding BorderPane to the scene and loading CSS
          Scene scene = new Scene(bp);
  
          scene.getStylesheets().add(getClass().getClassLoader().getResource("UI/login.css").toExternalForm());
          primaryStage.setScene(scene);
          primaryStage.setTitle("Test Login");
          /*primaryStage.titleProperty().bind(
                  scene.widthProperty().asString().
                          concat(" : ").
                          concat(scene.heightProperty().asString()));*/
          primaryStage.setResizable(false);
          primaryStage.show();
      }
  
  
      public static void main(String[] args) {
          launch(args);
      }
  }
  </code></pre>
  
  <p>CSS file :</p>
  
  <pre><code>#root {
      -fx-background-color:  linear-gradient(lightgray, gray);
      -fx-border-color: white;
      -fx-border-radius: 20;
      -fx-padding: 10 10 10 10;
      -fx-background-radius: 20;
  }
  
  #bp {
      -fx-background-color:  linear-gradient(gray,DimGrey );
  
  }
  
  #btnLogin {
      -fx-background-radius: 30, 30, 29, 28;
      -fx-padding: 3px 10px 3px 10px;
      -fx-background-color: linear-gradient(orange, orangered );
  }
  
  #text {
      -fx-fill:  linear-gradient(orange , orangered);
  }
  </code></pre>
  
  <p>If I run <code>mvn jfx:jar</code>, I get the jar file, but it also has the same problem. Why is that if it's a Maven project, JavaFX has problem finding files. ANy help would be nice. Thank you. </p>