Yes, you can load Clojure code from Java and invoke it however you like:
RT.var("clojure.core",
"require").invoke(Symbol.intern("your.namespace.here"));
And now you can use your clojure fns:
Var myfn = RT.var("your.namespace.here", "myfn");
myfun.invoke(arg1, arg2, etc);
I'd like to have a more pleasant Java/host API for loading code (that
first line is a doozy if you don't know what's going on), but it works.
Deploying a clojure app into a servlet container doesn't require any
special maneuvers -- yes, gen-class a single servlet. Map it to the
root you want in your web.xml (just to '/' if it's an all-Clojure
webapp), and you're done. The code in your gen-class'ed namespace
takes over from there, and you're in Clojure land from there on out.
Autowiring probably won't work with proxied classes, although I've
never tried it. Should work fine with gen-class'ed classes, as well
as deftype and defrecord classes.
- Chas
On Jun 19, 2010, at 2:23 PM, Todd wrote:
Is it possible to load up .clj files from the classpath of an
arbitrary java app? For example, could you proxy HttpServlet and run
your servlet as a .clj from within a servlet container? If not, and
you have to gen-class the servlet, could the servlet bootstrap the
clojure environment and proceed to load additional .clj files off
the classpath?
Essentially, I'm trying to figure out the easiest path to
incorporate clojure code into an existing java+tomcat environment
(although I think this is interesting in many other cases, too.)
Along this note, someone asked a question awhile back about
integrating spring with clojure. Is it possible to autowire either
proxy or gen-class clojure classes? If so, does anyone have any
experience with this scenario?
-Todd
On 6/19/10 10:39 AM, Paul Moore wrote:
On 19 June 2010 17:22, Chas Emerick<cemer...@snowtide.com> wrote:
If you're just looking to run a script that happens to be on the
classpath,
you can do so by prepending an '@' character to the classpath-
relative path
to the script.
So, if a directory foo is on your classpath, and a clojure file
you'd like
to run is at foo/bar/script.clj, then you can run it with:
java -cp<your_classpath_here> clojure.main @/bar/script.clj
FWIW, this is noted in the documentation for clojure here:
http://clojure.org/repl_and_main
Nice! Thanks.
Paul.
--
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
--
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