Dynamic Reload of Static Assets

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Dynamic Reload of Static Assets

Dustin Whitney
Hey all,

I thought this might be helpful to others, since it took me a couple of hours of futzing around to figure out.  Doug and I discussed this a while back at one our meetups: how do you get static resources to auto-reload without shutting down the server.  The problem is when the server is running, you can't trigger a build, so static assets are never pushed over to the target directory, so trying to load static assets from the classpath won't work.

So where is what I came up with:

    Http(DefaultContext.port).context("/public"){ ctx: ContextBuilder =>
      ctx.resources(new java.net.URL(DefaultContext.resourcesUrl))
    }
    .filter(...)
    .run

And here DefaultContext.resourcesUrl is a string that looks like:

file:///path/to/my/scala/project/src/main/resources/public

My DefaultContext uses configgy to load variables from a config file.  

I think Doug was trying to get a runnable jar going without needing it exploded in order to work correctly - this doesn't solve that, but it will reload assets, which is what I needed. I am having trouble getting the ProGuard plugin to work with akka, so I think I'll not go down the runnable jar route anyhow.

Dustin
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic Reload of Static Assets

n8han
Administrator
  On 10/07/2010 07:14 AM, Dustin Whitney [via Databinder] wrote:

> So where is what I came up with:
>
>     Http(DefaultContext.port).context("/public"){ ctx: ContextBuilder =>
>       ctx.resources(new java.net.URL(DefaultContext.resourcesUrl))
>     }
>     .filter(...)
>     .run
>
> And here DefaultContext.resourcesUrl is a string that looks like:
>
> file:///path/to/my/scala/project/src/main/resources/public

If these are resources that may change on the live server it's
definitely the way to go. I wonder if context should have a resources
method that's overloaded for File to make it more self-documenting, or
if we should just document it. I'll document that method now, probably a
good place to start.

Nathan