appengine-silver-120x30.gifThere are a lot of questions about serving static files in the development edition of google app engine. There are also a few answers, but none of them gave me a clear solution. Therefore I decided to look for one myself. In the end I have created a sub-optimal solution that works for me. So maybe it can work for you as well.

Read on to find out what I did.

Google app engine uses the concept of static files. This is a performance optimization. Using the file appengine-web.xml you can configure the way google handles static files. You can include and exclude certain files using their extension or name. More information can be found here at google. This all works nice in the online version, however there seems to be a problem with the development server. Some solutions try to configure the local version as well, still that did not work for me. I decided to look for a servlet that serves static files. Yes it can be that easy.

Check the following post serving static content using a servlet. This post gives you a servlet implementation to serve static files. I used the StaticServlet.java, read the post for more information. Adding this servlet to your web.xml solves the problems in your local environment.

    <servlet>
        <servlet-name>default</servlet-name>
        <servlet-class>org.yourscrum.web.StaticServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    
    <servlet-mapping> 
        <servlet-name>default</servlet-name> 
        <url-pattern>*.png,*.jpg,*.css,*.js</url-pattern> 
    </servlet-mapping>

That is it, now you can test your stuff locally and all your scripts, images, styles are loaded by your application. Of course you have to remove this servlet before uploading your application.

Hope it helps people with their local debugging of jquery scripts or other javascript things. Speaking about jquery, the next post will be about a component used for sorting items using the jquery ui component. I had an issue adding an image to the items in the sortable component.

Serving static files in Google app engine development edition
Tagged on: