Skip to content

Instantly share code, notes, and snippets.

@denlab
Created May 26, 2012 13:52
Show Gist options
  • Save denlab/2794041 to your computer and use it in GitHub Desktop.
Save denlab/2794041 to your computer and use it in GitHub Desktop.
package cljinject;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import clojure.lang.Compiler;
import java.io.StringReader;
public class SwankServletContextListener implements ServletContextListener{
// keep a hand on the context so we can get it from within clojure
public static ServletContext context;
public void contextInitialized(ServletContextEvent contextEvent) {
context = contextEvent.getServletContext();
// set variable to servlet context
context.setAttribute("TEST", "TEST_VALUE");
new Thread() {
public void run() {
try {
final String startSwankScript =
"(ns my-app\n" +
" (:use [swank.swank :as swank]))\n" +
"(swank/start-repl) ";
Compiler.load(new StringReader(startSwankScript));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}.start();
}
public void contextDestroyed(ServletContextEvent contextEvent) {
context = contextEvent.getServletContext();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment