How To Integrate Clojure Web Applications in Apache

后端 未结 7 790
萌比男神i
萌比男神i 2021-01-30 02:33

Note

Given this OP was written about two years ago, rather than ask the same question again, I am wondering if step-by-step instructions exist, so t

相关标签:
7条回答
  • 2021-01-30 02:42

    I use a combination of the following to make this fairly painless:

    Cake (incl. the deploy command)

    A Cake template for webprojects developed by Lau Jensen.

    Vagrant (Ruby VM(Virtualbox) management tool, which relies on Chef or Puppet)

    VPS (from Slicehost)

    The key part is the webdev template that Lau made. The webdev folder should be placed in the ~/.cake/templates. To create a new project based on it use:

    cake new webdev *projectname*
    

    Pls note that the template includes log4j and Java mail which can/should be excluded if not needed. It further assumes you are using Enlive and Moustache but changing that to Compojure/Hiccup is trivial if that is your poison.

    The template takes care of serving the app from jetty in development (you just eval server.clj) and works as a war when running under Tomcat. Routes remain identical if deployed to the server as ROOT.war under Tomcat. All static files should be located in the resources dir. Jetty will serve them from there (thanks to the Ring file middleware). In production these are moved to the root of the webapp and served from there by Tomcat(the web.xml takes care of that).

    The devbox folder contains a Vagrantfile and cookbooks necessary to create a Virtualbox VM with Tomcat installed. I use cake to deploy the .war file to the /home/vagrant dir (this is controlled from the definition of the dev context in project.clj). The .war file is symlinked into Tomcat's webapps dir (/var/lib/tomcat6/webapps) as ROOT.war. For further info on how to use Vagrant please see the Vagrant site.

    This gist shows an example of how to adapt the project.clj to use the cake deploy command. The example creates two contexts @dev and @prod which you can deploy to using:

    cake deploy @dev / cake delpoy @prod
    

    I have collected the Cake webdev template and the Vagrant files in this zip.

    0 讨论(0)
  • 2021-01-30 02:44

    I've had some success using leiningen-war to generate a generic war file (assuming you are using leiningen, of course). It allows you to specify locations for static html, the location of a web.xml and other resources in your project.clj file.

    It wasn't too difficult for me to produce a generic war file that I was able to deploy to JBoss (running Tomcat as a servlet container) but I think you have to be pretty familiar with the web.xml format. I'm more comfortable with authoring my own web.xml so that may account for my liking this approach more.

    It appears that the person behind leiningen-war is recommending lein-ring now. I've started looking at that but so far I haven't been able to get a generic war file from it as easily.

    I agree though that accounting for production deployment is a weakness here.

    0 讨论(0)
  • 2021-01-30 02:44

    If you're deploying on Google App Engine, here's a great blog http://compojureongae.posterous.com/

    You may still get some useful tips even if you're not deploying to GAE.

    0 讨论(0)
  • 2021-01-30 02:55

    I am using Noir, a web framework built on top of Ring and Compojure.

    I have created project using lein noir new my-proj. Then I created my-proj/web directory and added following lines to

    project.clj:    
        :compile-path "web/WEB-INF/classes"
        :library-path "web/WEB-INF/lib"
        :ring {:handler project.server/handler}
    

    I have set my-proj/web directory as context root during development for Tomcat.

    For static file serving, I put stuff under my-proj/resources/public directory. For accessing (read/write) files through code, :servlet-context from ring request header can be used. With above settings, contextual path would be: (.getRealPath (ring-request-header :servlet-context) "/WEB-INF/classes/myfile.txt"). Myfile.txt is under my-proj/resources.

    0 讨论(0)
  • 2021-01-30 02:57

    People are deploying Compojure apps to non-Jetty servlet containers.

    Check out:

    • https://github.com/weavejester/lein-ring
    • https://github.com/weavejester/lein-beanstalk

    Also check out lein-war

    0 讨论(0)
  • 2021-01-30 03:00

    If you are using a ring-based server (compojure, noir/lib-noir, luminus, etc.), and want to deploy as an uberjar, to avoid

    "Failed to load Main-Class manifest attribute from your-uberjar.jar"
    

    simply create the uberjar with lein ring uberjar. Note the 'ring' addition to lein uberjar. This is assuming you're using the lein-ring plugin.

    0 讨论(0)
提交回复
热议问题