.scala configuration file instead of
.sbt, so let’s add dependency into
project/build.scala. Take Dojo for example.
To view this dependency in Eclipse, you need to run
sbt eclipse again. In the Referenced Libraries section, you can see a
dojo-1.9.3.jar, and the library lies in
ProjectNameStack.scala file and add the following lines at the bottom of the trait:
That’s it! Now you can refer to the WebJars resources in views, like this:
/webjars/*is a Wildcards and
params("splat")is to extract the asterisk part.
resourcePathpoints to the WebJars resources in the jar file, as we saw in Eclipse. It is then fetched as an
servletContext.getMimeType()is a handy method to determine the content type of the requested resource, instead of parsing it by ourselves. I find this in SpringMVC’s ResourceHttpRequestHandler.
IOUtilis a utiliy class that comes with Scalate, so don’t forget to import it first.
At first I tried to figure out whether Scalatra provides a conveniet way to serve static files in classpath, I failed. So I decided to serve them by my own, and this gist was very helpful.
Anyway, I’ve spent more than half a day to solve this problem, and it turned out to be a very challenging yet interesting way to learn a new language, new framework, and new tools. Keep moving!