Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Embedding Clojure/swank into existing Java system
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Anton Vodonosov  
View profile  
 More options Nov 28 2008, 9:37 pm
From: Anton Vodonosov <avodono...@gmail.com>
Date: Fri, 28 Nov 2008 18:37:52 -0800 (PST)
Local: Fri, Nov 28 2008 9:37 pm
Subject: Embedding Clojure/swank into existing Java system
Hello.

I want to embed Clojure into a Java system we are creating at work to
have interactive control on it (via SLIME) during development. The
system is running in Tomcat.

I did not find a conventional to do this. Therefore I copy/pasted
peace of clojure.lang.Repl class and created a JSP page, that starts
Clojure and swank when executed. The JSP may be found here:
http://paste.lisp.org/display/71206.

It is quite simple and works OK, but I dislike the copy/pasting of
clojure.lang.Repl code. Is there a better way to embed swank into a
Java system?

Best regards,
- Anton


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Craig McDaniel  
View profile  
(1 user)  More options Dec 1 2008, 11:46 am
From: Craig McDaniel <craig...@gmail.com>
Date: Mon, 1 Dec 2008 08:46:49 -0800 (PST)
Local: Mon, Dec 1 2008 11:46 am
Subject: Re: Embedding Clojure/swank into existing Java system
Since release 1127, you can now do this instead:

$ cat src/mypkg/HelloServlet.clj
(ns myapp.HelloServlet
  (:gen-class
   :extends javax.servlet.http.HttpServlet)
  (:import (java.io PrintWriter)
           (java.util.logging Logger Level))
  (:require swank clojure.main))

(defn- -init [this config]
  (clojure.main/with-bindings
   (swank/ignore-protocol-version "2008-11-23")
   (swank/start-server "/dev/null" :port 4006 :encoding "iso-latin-1-
unix")))

(defn- -doGet [this request response]
  (.severe (Logger/getLogger "hello") "logging this thang")
  (.setContentType response "text/html")
  (let [out (PrintWriter. (.getWriter response))]
    (doto out
      (.println "<html>")
      (.println "<head>")
      (.println "<title>Hello World!</title>")
      (.println "</head>")
      (.println "<body>")
      (.println "<h1>Hello Bizarro World...from Clojure!</h1>")
      (.println (str "17 + 33 = " (+ 17 33)))
      (.println "</body>")
      (.println "</html>"))))

It doesn't handle the unloading/reloading of servlets well, so it
could be improved by:

1. Letting swank pick which port to listen on, and writing the port
number to a temporary file.
2. On unload, closing the swank socket and deleting the temporary
file.

I posted the whole project (build.xml, etc...) here: http://paste.lisp.org/display/71326

I'm also going to try installing a Compojure-built servlet into
Tomcat. I'll post that later if I can make that work.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Craig McDaniel  
View profile  
 More options Dec 1 2008, 2:09 pm
From: Craig McDaniel <craig...@gmail.com>
Date: Mon, 1 Dec 2008 11:09:47 -0800 (PST)
Local: Mon, Dec 1 2008 2:09 pm
Subject: Re: Embedding Clojure/swank into existing Java system
Never mind about my unloaded/reloading servlets comment. Checking for
a swank exception as in the original example would work fine.

-Craig


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Anton Vodonosov  
View profile  
 More options Dec 3 2008, 5:17 pm
From: Anton Vodonosov <avodono...@gmail.com>
Date: Wed, 3 Dec 2008 14:17:29 -0800 (PST)
Local: Wed, Dec 3 2008 5:17 pm
Subject: Re: Embedding Clojure/swank into existing Java system
Hi Craig,

clojure.main/with-bindings was exactly what I needed.
With it my JSP became trivial few liner: http://paste.lisp.org/display/71541

Thank you.

- Anton


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google