Question

I've written a little internal webapp that I use to import invoices from our jobcard database into MYOB. I've written it using Clojure and Compojure, and it actually works pretty well, and it was also a good learning exercise for me.

However, I've got a problem, it seems that after a successful invoice import the jetty server will no longer serve the static CSS file.

The defroute is as follows:

(defroutes static-routes
  (GET ["/:filename" :filename #".*"] [filename]
       (response/file-response filename {:root "public"})))

(The file is just css/default.css, it works just perfectly before the first import.)

Now I think I've found the problem, it seems that the MYOB ODBC driver is changing the working directory of the Jetty server (and my REPL), because when I enter the following in the REPL:

(file-seq (File. "."))

I get a listing of my Temp files directory, which would explain why my CSS file is no longer being found.

The odd thing is, if I do:

(.getAbsolutePath (File. "."))

I get the correct directory of my application.

Does anyone know of something (other than coding in an absolute path) that can get around this quirk of the MYOB ODBC driver?

I'm guessing that I could just grab and store the absolute path when I start up, but would that work with an uberjar?

Edit: It seems that it is impossible to fix due to limitations in the JVM?

How do I change directory in command line with Clojure?

Was it helpful?

Solution

There doesn't really seem to be much that can be done about this. It just seems that the MYOB ODBC bridge is just bad.

So in order to get around this, I've replaced my relative file calls to use .getAbsolutePath.

e.g.

(java.io.File. (.getAbsolutePath (java.io.File. "templates/index.html")))

I've also changed it so static file requests use a absolute file path:

(defroutes static-routes
  (GET ["/:filename" :filename #".*"] [filename]
       (response/file-response filename {:root (.getAbsolutePath (java.io.File. "public"))})))

I haven't just tried creating an uberjar, so I expect I might get some problems there.


Just an update to this, using Compojure's resources function seems to skip with problem entirely, also working without problems when creating an UberJar.

So I no longer have "static-routes" defined anymore, I just use:

 (route/resources "/")

And have the files in my resources/public directory in the root directory of my project.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top