| Paste number 71209: | JSP page to start embedded Clojure/swank |
| Pasted by: | avodonosov |
| When: | 1 year, 2 months ago |
| Share: | Tweet this! | http://paste.lisp.org/+1IY1 |
| Channel: | None |
| Paste contents: |
<%--
This JSP page is intended to start swank-clojure
in a running Java system, executed in an HTTP
container like Tomcat, so that you can connect to
it from SLIME and interactively inspect, control and
modify it.
Place this JSP in your web application directory,
place clojure.jar into WEB-INF/lib.
When you open the JSP page using browser, it will
start swank listening on the port 7777. Now you
can connect to it from Emacs using M-x slime-connect
(assuming, of course, that you have swank-clojure
installed; good instructions for this may be
found at http://bc.tech.coop/blog/081023.html).
Tested with Clojure svn revision 1128,
swank-clojure revision 886d66ed571fe2908de4f5714c735ab48054d587.
Anton Vodonosov, 2008-11-29
--%>
<%@page import="clojure.lang.Compiler"
import="clojure.lang.Var"
import="clojure.lang.RT"
import="clojure.lang.Symbol"
import="java.io.StringReader"
import="java.io.PrintWriter" %>
<%!
// The code is mostly copy/pasted from
// clojure.lang.Repl class;
static final Symbol USER = Symbol.create("user");
static final Symbol CLOJURE = Symbol.create("clojure.core");
static final Var in_ns = RT.var("clojure.core", "in-ns");
static final Var refer = RT.var("clojure.core", "refer");
static final Var ns = RT.var("clojure.core", "*ns*");
static final Var compile_path = RT.var("clojure.core", "*compile-path*");
static final Var warn_on_reflection = RT.var("clojure.core", "*warn-on-reflection*");
static final Var print_meta = RT.var("clojure.core", "*print-meta*");
static final Var print_length = RT.var("clojure.core", "*print-length*");
static final Var print_level = RT.var("clojure.core", "*print-level*");
static final Var star1 = RT.var("clojure.core", "*1");
static final Var star2 = RT.var("clojure.core", "*2");
static final Var star3 = RT.var("clojure.core", "*3");
static final Var stare = RT.var("clojure.core", "*e");
static void startSwank() throws Exception {
// Clojure script to start swank.
// It is copy/pasted from the *inferior-lisp*
// buffer, after Clojure/SLIME was started
// from Emacs.
final String startSwankScript =
"(add-classpath \"file:///c:/usr/unpacked/clojure/swank-clojure/\")" +
"(require (quote swank))" +
"(swank/ignore-protocol-version \"2008-11-23\")" +
"(swank/start-server \"nul\" :encoding \"utf-8-unix\" :port 7777)";
try
{
Var.pushThreadBindings(
RT.map(ns, ns.get(),
warn_on_reflection, warn_on_reflection.get(),
print_meta, print_meta.get(),
print_length, print_length.get(),
print_level, print_level.get(),
compile_path, "classes",
star1, null,
star2, null,
star3, null,
stare, null));
//create and move into the user namespace
in_ns.invoke(USER);
refer.invoke(CLOJURE);
Compiler.load(new StringReader(startSwankScript));
} finally {
Var.popThreadBindings();
}
}
%>
<%
String message;
try {
startSwank();
message = "swank has been started";
} catch (Throwable e) {
message = "Exception occurred at swank startup attempt: "
+ e.getMessage()
+ ".<br/> Perhaps swank was already running.";
}
%>
<%= message %>
This paste has no annotations.