1

i need to load an fxml based JavaFX Scene in Clojure, but when i try to load the resource "view.fxml" it returns nil.

Here is my present code:

(ns ui.ui_controller
(:import (javafx.application Application)
       (javafx.fxml FXMLLoader)
       (javafx.scene Scene)
       (javafx.stage Stage)))

(gen-class
:name ui.ui_controller
:extends javafx.application.Application)

(defn -main [& args]
(Application/launch ui.ui_controller args))

(defn -start [this stage]

 (let [loc (clojure.java.io/resource "view.fxml") 
    root (FXMLLoader/load loc)]

(.setScene stage (Scene. root))
(.setTitle stage "JavaFXML with Clojure Example")
(.show stage)))

And in the resources folder is the view.fxml file, which should be loaded.

When in call (println (clojure.java.io/resource "view.fxml")) it returns nil...

Any idea what goes wrong here?

Thanks!

GameYoker
  • 55
  • 7
  • I am guessing there is something wrong in your environment. Try making a new project for testing, with a one-line text file in `resources`. You should be able to read it with `slurp`. – Alan Thompson Jan 03 '17 at 17:00
  • Thanks! I made a new project and it works. I will make a new project for my application to. – GameYoker Jan 04 '17 at 11:53
  • I added :resource-paths [["lib/jfxrt.jar"] to my project.clj, i don't know why...after deleting it, it works. – GameYoker Jan 04 '17 at 14:56
  • I think you have just demonstrated that the default setting is `:resource-paths ["resources"]`, and that you had inadvertently overwritten it. – Alan Thompson Jan 04 '17 at 15:04

1 Answers1

1

Here is an example

(ns tst.clj.core
  (:use clj.core
        clojure.test )
  (:require
    [clojure.java.io :as io]
  ))

(def words (slurp (io/file (io/resource "count.txt"))))
(println words)


> ls -ldF resources/count.txt 
-rw-rw-r-- 1 alan alan 14 Jan  3 09:01 resources/count.txt

> cat resources/count.txt
one
two
three

> lein test

one
two
three
Alan Thompson
  • 29,276
  • 6
  • 41
  • 48