Creating WAR for a Noir project using lein-ring

489 views
Skip to first unread message

clj-noob

unread,
Jul 26, 2011, 9:29:24 AM7/26/11
to clj-...@googlegroups.com
How to create a war for a Noir project using lein-ring?
I have tried by adding :ring {:handler noir.server/gen-handler} to project.clj. The war and uberwar commands (lein ring uberwar) generated war file, but it does not give any response.

semperos

unread,
Jul 26, 2011, 12:48:39 PM7/26/11
to clj-...@googlegroups.com

Chris Granger

unread,
Jul 26, 2011, 1:01:34 PM7/26/11
to clj-...@googlegroups.com
Yeah take a look at that example.

The problem is that you're setting your handler to the gen-handler function, when you really need it to be the *result* of calling gen-handler:

(def my-cool-site (server/gen-handler))

:ring {:handler myns/my-cool-site}

Cheers,
Chris.

clj-noob

unread,
Jul 26, 2011, 3:53:38 PM7/26/11
to clj-...@googlegroups.com
Thanks for the pointers. But I ran into another problem. I created a noir-test project:
$lein noir new noir-test
$lein run
This works fine.
To create war, I added :ring handler to project.clj file. I have put function def after calling load view. Created war, and deployed to tomcat. Accessing root url gives FileNotFoundException about WEB-INF/classes/public and /welcome gives noir error page.

To make sure that lein-ring works fine, I have tested lein-ring plugin against lein new project. The generated war file works fine for this new ring project.

Chris Granger

unread,
Jul 26, 2011, 8:38:19 PM7/26/11
to clj-...@googlegroups.com
I'll take a look tonight. It's likely an issue with the way resource routes are set up.

Cheers,
Chris.

Chris Granger

unread,
Jul 27, 2011, 12:05:21 AM7/27/11
to clj-...@googlegroups.com
Did you do lein ring uberwar? It worked for me, except it was missing the noir logo, but that's not unexpected given that it doesn't add lib jars' resources to the war's public dir.

As a side note, Tomcat is annoying to install :-p

Cheers,
Chris.

clj-noob

unread,
Jul 27, 2011, 1:14:10 AM7/27/11
to clj-...@googlegroups.com
Yes I did lein ring uberwar. And it is not working for noir projects for me :(  I am working on snow leopard (I am not sure if it does matter).
I guess it is not only resource routes, but all the routes as welcome page is also not showing up.
May be something additional needs to be done. Anyways, I will further look into it. I am very keen on including Noir in my web stack.

I do use NetBeans for other projects on my dev machine, and tomcat installation was a breeze as it is part of NetBeans distribution.

By the way the tutorials are great.

Chris Granger

unread,
Jul 27, 2011, 1:24:19 AM7/27/11
to clj-...@googlegroups.com
Can you send me your war?

Cheers,
Chris.

Chris Granger

unread,
Jul 27, 2011, 3:24:54 AM7/27/11
to clj-...@googlegroups.com
Ok, so after banging my head against a wall for a bit, I realized that the problem is very simple :)

(server/load-views "src/war_test/views/")

That directory doesn't exist in the war, so no views are loaded. You just need to require your views explicitly at the top of your server.clj, e.g:

(ns war-test.server
  (:require [noir.server :as server]
            [war-test.views.welcome]
            [war-test.views.common]))

Then it should work fine :) Also, a good thing to note: always do lein clean before you create a new version of the war, it doesn't seem to always pick up changes otherwise.

Cheers,
Chris.

Chris Granger

unread,
Jul 27, 2011, 3:55:52 AM7/27/11
to clj-...@googlegroups.com
I also create a vnext branch for me to make changes for the next version in (follow along if you'd like!) that has a better load-views function called load-views-ns.


Usage like so:

(server/load-views-ns 'war-test.views)

You can grab the latest noir via [noir "1.1.1-SNAPSHOT"].

Cheers,
Chris.

semperos

unread,
Jul 27, 2011, 6:41:08 AM7/27/11
to clj-...@googlegroups.com
Very nice. One further point: any reason why we can't have multiple namespace roots for looking for views? I've been playing around with "modularizing" my Ring apps, a la Django apps, and it would be helpful not to have to have separate calls to load-views-ns just to capture views in different namespaces.

Thoughts?

clj-noob

unread,
Jul 27, 2011, 7:29:59 AM7/27/11
to clj-...@googlegroups.com
Chris, yes this was the problem. Do you think update to tutorials will help people like me? I can send you a patch.

I do not have github account yet, but I will create one to follow Noir vnext branch.

Chris Granger

unread,
Jul 28, 2011, 3:12:45 PM7/28/11
to clj-...@googlegroups.com
Semperos,

Submit a patch and I'll include it :)

Cheers,
Chris

semperos

unread,
Jul 28, 2011, 4:17:45 PM7/28/11
to clj-...@googlegroups.com
Done :)

Thanks for being flexible. I did some initial testing at the REPL and ran the test suite, no issues were readily apparent.

-Daniel (semperos)
Reply all
Reply to author
Forward
0 new messages