The servlet interface includes the init method for this exact purpose. In java, this would be used by subclassing one of the abstract servlet classes, and filling in the init method with whatever initialization you need. Or by implementing the servlet interface directly.
>From the javadoc, the init method "Initializes the servlet. The method is called once, automatically, by the servlet engine when it loads the servlet. It is guaranteed to finish before any service requests are accepted." I find this approach more straightforward than having an entire separate servlet for initialization. I was hoping that initialization of this kind would make it into the ring spec, but there wasn't much support. See the thread below for more details: http://groups.google.com/group/ring-clojure/browse_thread/thread/ec5a30b5bb4ec823# Rob On Nov 27, 4:50 pm, Mike Meyer <mwm-keyword-googlegroups. 620...@mired.org> wrote: > My simple web app > (http://blog.mired.org/2010/11/x10-controller-in-clojure.html) has > some stuff that needs to happen just once (in this case, opening the > serial port). It's not clear how to get this to happen using ring. If > I do it inside my ring handler, then it gets run on every request, and > I have to check to make sure it's not run multiple times. If I run it > outside the handler, then it gets run when I do "lein uberwar", which > is simply wrong. > > When the deployment platform activates the war would seem to be the > right time to run this ("war load time"?). So maybe this is a question > that depends on the deployment platform, or war? However, a quick > google search didn't turn up anything that looked interesting. > > Anyone got suggestions on how to set up code to be run when Jetty (or > tomcat, or ...)? > > thanks, > <mike > -- > Mike Meyer <m...@mired.org> http://www.mired.org/consulting.html > Independent Network/Unix/Perforce consultant, email for more information. > > O< ascii ribbon campaign - stop html mail -www.asciiribbon.org -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en