Relative file paths differ between Jetty and Tomcat?

Skip to first unread message

Simon Brooke

Apr 14, 2014, 11:14:22 AM4/14/14
I've written a little web-app which uses data stored as text files. I created the project as a luminus web project, using

lein new luminus

so it has the default luminus setup. I stored my datafiles in resources/public/txt, and referred to them in my functions using
  14 (defn generate-nonsense [request-map]
  15     (let [file (str "resources/public/txt/" (:file request-map))
  16           depth 3
  17           length (read-string (:length request-map))]
  18       (synthesise/write-output
  19         (synthesise/compose-nonsense
  20           (analyse/analyse-file file depth)
  21           length) true)))

That works fine when you run it from

lein ring server-headless

which as I understand it is actually running Jetty; but when I packaged it using

lein ring uberwar

and sent the resulting WAR file up to my (tomcat) server, it failed with file not found errors. So, what would the file path be when running from a WAR file, why is it different from Jetty, and is there any code which will resolve to the same path whether called from Tomcat or Jetty (or, indeed, other Servlet containers?)

James Reeves

Apr 14, 2014, 4:33:47 PM4/14/14
When in your project directory, certain directories, such as src and resources, are added to the classpath. When you turn your project into a war or jar file, these top-level directories disappear, and their contents folded together within the resulting war or jar.

Referring to resources by filepath is therefore very fragile. In your project directory, the filepath might look like:


But when compiled into a jar, it would be:


And in a war:


That's why your code won't work outside your project repository.

Instead, you should be using the `` function, which returns a URL pointing to the file. You can slurp this file, or open an input-stream or reader to it using the functions in

- James

You received this message because you are subscribed to the Google Groups "Clojure Web Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
For more options, visit

Reply all
Reply to author
0 new messages