.war packaging and static files

1,485 views
Skip to first unread message
Message has been deleted

Chris Hoge

unread,
Sep 1, 2010, 2:23:06 PM9/1/10
to Compojure
I'm attempting to package up an application as a war file to deploy on
a Glassfish server. I'm trying to serve a modest amount of static
content: some .css and images files. Unfortunately I have no idea
where to place the files in the .war file to make them visible to the
compojure.route/files method.

(compojure.core/defroutes app
(compojure.route/files "/css")
(compojure.route/files "/images")
; rest of routes go here
)

(defservice app)

To create the war I create an uberjar that I put in WEB-INF/lib. I've
tried putting a public directory in the tld of the war and in the top
of the src directory (so it gets added to the uberjar), as well as
many other different configurations and places. Yet the application,
though running, can not serve up the static content.

The war file is being installed at the root of the server; i.e.
localhost:8080/

Does anyone have a clear and working example of how this is done?


Saul Hazledine

unread,
Sep 1, 2010, 4:07:14 PM9/1/10
to Compojure
On Sep 1, 8:23 pm, Chris Hoge <cch...@gmail.com> wrote:
> I'm attempting to package up an application as a war file to deploy on
> a Glassfish server. I'm trying to serve a modest amount of static
> content: some .css and images files. Unfortunately I have no idea
> where to place the files in the .war file to make them visible to the
> compojure.route/files method.
>
> Does anyone have a clear and working example of how this is done?

Sorry, I don't have an example to hand but I can let you know what
works for me.

I'd recommend reading the following overview for how a war file is
laid out:
http://oreilly.com/java/archive/tomcat.html

While using compojure to serve static files is great for development
I'd personally let the web container (Glassfish) serve the static
content for you - this is basically anything not in the WEB-INF
directory. You need to watch the URLs though since Glassfish may put
your application in a subpath so the css, say, is found at
http://whatever.com/my-app/css rather than http://whatever.com/css.

If you really need read files into your clojure code after deployment
the most common way is to put them into WEB-INF/classes and then load
them as a resource.

If you're using leiningen then leiningen-war plugin might useful to
you as it will build the war file from typical leiningen build
directories.

Saul

Remco van 't Veer

unread,
Sep 2, 2010, 2:52:03 AM9/2/10
to comp...@googlegroups.com
Static files should go in the root of a war file and will be served by
the web container (glassfish in your case) directly. You do not need
compojure routes for them.

Chris Hoge

unread,
Sep 2, 2010, 1:28:50 PM9/2/10
to Compojure
Ok, I see. For the edification of others, I'm attaching my web.xml
configuration. All of the static files get dropped into the top level
directory of the war (not in css or images directories, which is
surprising to me). The default app that's included with Glassfish
seems a bit crude, but it works. Thanks.

<web-app>
<servlet>
<servlet-name>compojureapp</servlet-name>
<servlet-class>app.CompojureApp</servlet-class>
</servlet>
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</
servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>compojureapp</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/css/*</url-pattern>
<url-pattern>/images/*</url-pattern>
</servlet-mapping>
</web-app>
Reply all
Reply to author
Forward
0 new messages