3

Note

The following question is similar to this SO post, but I am asking a slightly different question two years later.

Is it possible to run Clojure programs, like those created from lein new noir or a program that expects to process httpd from Apache without running Tomcat or having to install a Jetty server, much the way Perl programs can run with mod_perl and Python programs can run most typically with mod_wsgi?

Am I missing the point because Clojure web applications behave more like Java servlets, and need to be handled similarly to JSPs?

I am asking this, because I have a full Apache system already set up and configured, and would like the simplest way to introduce Clojure web applications into that environment.

Community
  • 1
  • 1
octopusgrabbus
  • 10,555
  • 15
  • 68
  • 131
  • 2
    Why was this downvoted? Seems a reasonable enough question to me. – JohnJ May 13 '13 at 20:22
  • This is a bit of a weird question. Can you go into more detail about what you mean by a Clojure program? You can write code in *any* language that integrates with Apache via **CGI** (I once wrote a status console written in bash…). If however you mean a Clojure program that is built as a standard "webapp", with a Servlet and so on, that the author expected to be deployed in a web container, then isn't the answer to this question identical to if we were just talking about Java? – SCdF May 13 '13 at 22:02
  • (the answer to "running Servlets without a web container" is, I believe, no. You'd have to write a bunch of glue code, which would end up with you basically reinventing web containers...) – SCdF May 13 '13 at 22:04
  • With a normal apache module setup, iirc, the program is run fresh for every request. This does not play nicely with JVM startup times. It should be possible, but pragmatically you would have to do some work arounds to not have long page load latency, bad resource usage, and bad overall performance. – noisesmith May 13 '13 at 23:42
  • 1
    @SCdF Edited OP and title. – octopusgrabbus May 14 '13 at 12:28
  • Right, so yeah, Jetty (or really any of your favourite mini-web containers) is your man :-) – SCdF May 14 '13 at 20:11

1 Answers1

7

the short answer is: not reasonably.

In theory any program can be run by Apache and have requests proxied to it, and so you could write a program in clojure that expected web requiests from stdin and then write a mod_clojure that would pass the requests though none of the popular web frameworks would do this for you, and this would have some undesirable performance characteristics (intentional understatement).

The shortest path I see is to write a normal clojure ring application and run it in jetty, then have apache proxy the appropriate requests to it.

Arthur Ulfeldt
  • 90,827
  • 27
  • 201
  • 284