Created
May 26, 2012 13:52
-
-
Save denlab/2794041 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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