Assuming your environment is set up properly w.r.t. classpaths, spring should work just fine in a REPL. We use spring security for our compojure webapp, and the spring context starts up as expected in our enclojure REPLs. FWIW, we do use maven and the clojure-maven-plugin, which informs NetBeans (and therefore enclojure) of our classpath. You didn't say what you're using for build tooling, but I presume it's either ant- or maven-based if you've got a large established spring- related codebase. If it's the latter, you should be able to drop clojure-maven-plugin into your pom, run clojure:swank, and have a REPL with the spring dependencies and configs ready to go.

Another option is to embed a REPL server into your application. Enclojure has a server REPL library (~12K, IIRC) which you can use to start up a REPL on a given port, and then one can connect to it from enclojure, and monkey with the host app however you want (% static class compilation, etc). This is how I do 75% of all my development. I presume swank/slime have a similar arrangement.

But: invoking clojure.main.main programmatically?  Ouch. :-)

- Chas

On Mar 31, 2010, at 11:18 PM, Josh Daghlian wrote:

I greatly appreciate the excellent recent spate of “getting started”
discussions/docs, and I’ve had no trouble at all in bootstrapping new
Clojure projects. But I wonder if there is (yet? anymore?) a canonical
way of embedding Clojure into my existing codebase without refactoring
my existing deployment model. Everything I’ve seen on the web on the
subject is at least a year old.

A repl is a great debugging and diagnostic tool (and it gives me an
excuse to use Clojure at work), but the embedding feels shadier than
I’m comfortable with. Here’s a cartoon:

public class ExampleMain {
private static ApplicationContext staticCtx;
public static void main(String[] args) {
   // About 30 man-years of effort is embodied in the following line,
including
   // lots of o-r mappings, database credentials, and many scattered
properties.
   staticCtx = loadSpringContext(“enormous-spring-file.xml”);

   if (args[0].equals(“shell-mode”)) {
       clojure.main.main(new String[]{}); // starts up more or less
instantly
   } else {
       doNormalWork(); // runs for many minutes before hitting
breakpoint
   }
   System.exit(0);
}
}

so then, thanks to having a static Spring context bean, I can then do
things like:

(def get-bean [beanname] (.getBean com.example.ExampleMain/staticCtx
beanname))
(def dao (get-bean “readOnlyJpaDao”))
;; now I can interrogate my big Oracle database...

(def customer-to-debug (.getCustomer dao “customerID4200000213”))
;; picked out a single Customer object; probably initialized a bunch
of JPA stuff, too

(map #(.getVisitTime %) (.getVisits customer-to-debug))
(count (filter #(> .getVisitTime % *last-week*) #(.getVisits customer-
to-debug)))
;; etc.

It's a vanilla repl (though running it in a shell in emacs helps).
What I’d *really* like to do is start up swank-clojure, pass locals
(like the Spring context, some timing information, etc.) into the
clojure environment, and so forth.

Apologies if I’m missing something obvious (although I suppose that’s
what “getting started” docs are for:).

Thanks.
--josh

--
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

To unsubscribe, reply using "remove me" as the subject.

--
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

Reply via email to