clojure.java.io/resource returns nil

455 views Asked by At

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!

1

There are 1 answers

0
Alan Thompson On BEST ANSWER

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