title: getResource of Class and Classloader null when running from jar
body: <p>After reading trough a bunch of Posts regarding the Resource System i'm still running into a wall with this one.</p>
  
  <p>The Scenario:</p>
  
  <p>I'm currently developing a javafx applicationm which should run both as a jar and as an Applet. 
  I'm using the simple trick <a href="http://docs.oracle.com/javafx/2/swing/swing-fx-interoperability.htm" rel="nofollow noreferrer">JavaFX into Swing Applications</a> to wrap my application into a fxpanel.</p>
  
  <p>Both Versions work fine in Eclipse.</p>
  
  <p>But now, both the jar and the Applet run into the same Problem, once the first fx Controller is invoked.</p>
  
  <p>My package structure:</p>
  
  <pre><code>/*
   1. 
      2.
          3.
              controller.
                          EntryPoint.class &lt;-- Main
                          MenuController.class
                          TabsController.class
              ui.
                  pane.
                          MainMenu.fxml
                          Startuppane.fxml
                          Tabs.fxml
                  note.
                          NoteSearch.fxml
                          NoteView.fxml
  
   */
  </code></pre>
  
  <p>//edit: Tree Command from my unpacked jar: <a href="http://pastebin.com/nmkPjkPF" rel="nofollow noreferrer">Pastebin</a> //edit End</p>
  
  <p>My application does the Following:</p>
  
  <p>First, It loads the RootLayout from EntryPoint.class</p>
  
  <pre><code>MainBorder = ROOTLOADER.load(EntryPoint.class.getResourceAsStream("/1/2/3/ui/pane/StartupPane.fxml"));
  </code></pre>
  
  <p>And then two Childs, a Menu, and some Tabs.</p>
  
  <p>The Menu Works fine, because the MenuController itself does not load any other childitems.</p>
  
  <p>Now the actual issue Comes in when the TabsController is invoked, and tries to load it's own childitems, such as the NoteView.</p>
  
  <pre><code>    TP  = TABSLOADER.load(EntryPoint.class.getResourceAsStream("/1/2/3/ui/pane/Tabs.fxml")); //Loading The Tabs.
  </code></pre>
  
  <p>So the TabPane gets loaded, and when the TabsController now tries to load his own Childitems. I always get a NullPointer, in the exported jar or the webapplet.</p>
  
  <p>I tried loading the ChildItems with the following Methods:</p>
  
  <pre><code>NOTE_SEARCH_LOADER.load(TabsController.class.getResourceAsStream("/1/2/3/ui/note/NoteSearch.fxml")); 
  </code></pre>
  
  <p>Works fine in Eclipse, but once exported causes Unknown Path / NullPointer</p>
  
  <pre><code>NOTE_SEARCH_LOADER.load(TabsController.class.getClassLoader().getResourceAsStream("1/2/3/ui/note/NoteSearch.fxml")); 
  </code></pre>
  
  <p>Using ClassLoader instead, removed first Slash. Works in Eclipse, once exported causes Unknown path / NullPointer</p>
  
  <pre><code>NOTE_SEARCH_LOADER.load(EntryPoint.class.getResourceAsStream("/1/2/3/ui/note/NoteSearch.fxml"));
  </code></pre>
  
  <p>Using the EntryPoint.class (main) with Absolute Path. Works in Eclipse, once Exported.  Unknown Path / NullPointer when exported.</p>
  
  <pre><code>NOTE_SEARCH_LOADER.load(EntryPoint.class.getClassLoader().getResourceAsStream("1/2/3/ui/note/NoteSearch.fxml"));
  </code></pre>
  
  <p>Using the ClassLoader from my Main Class, removed first Slash. Works in Eclipse, Unknown Path / NullPointer when exported.</p>
  
  <p>//edit3: I did another Test, copying the Code from the TabController into the EntryPoint. the EntryPoint Version of the Code works even after the Export to a Jar or Applet.</p>
  
  <p>I guess it has something to do, how the Controller is invoked?</p>
  
  <p>//edit End</p>
  
  <p>I am scratching my head, and wondering what else i could Try.</p>
  
  <p>//edit2: The NullPointer Causing FXML can be found at the given Location, when i unpack my fxml.</p>
  
  <p>//edit End</p>
  
  <p>Maybe i'm again just missing something very obvious.</p>
  
  <p>Sinclery</p>
  
  <p>Fabian95qw</p>
  
  <p>List of visited threads:</p>
  
  <p><a href="https://stackoverflow.com/questions/2593154/get-a-resource-using-getresource">Get a resource using getResource()</a></p>
  
  <p><a href="https://stackoverflow.com/questions/3861989/preferred-way-of-loading-resources-in-java">Preferred way of loading resources in Java</a></p>
  
  <p><a href="https://stackoverflow.com/questions/861500/url-to-load-resources-from-the-classpath-in-java">URL to load resources from the classpath in Java</a></p>
  
  <p><a href="https://stackoverflow.com/questions/19602727/how-to-reference-javafx-fxml-files-in-resource-folder">How to reference javafx fxml files in resource folder?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/14389731/how-do-i-use-java-getresource-to-get-a-resource-from-a-parent-directory">How do I use Java getResource() to get a resource from a parent directory?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/29877808/why-does-getresource-return-null">Why does getResource return null</a></p>