On Mar 25, 3:16 am, Berlin Brown <berlin.br...@gmail.com> wrote:
> On Mar 25, 3:12 am, BerlinBrown <berlin.br...@gmail.com> wrote:
>
>
>
> > I know it isn't advised but I have my various reasons.
>
> > What are some of the best ways to invoke clojure scripts from Java but
> > still maintain the state of the current session.
>
> > For example, if I run a script from Java, is there a way to ensure
> > that script has already been run...say if I run another script.
> > I was doing the following.
>
> > ----------------------
>
> > package test.toolkit.clojure;
>
> > import clojure.lang.Namespace;
> > import clojure.lang.RT;
> > import clojure.lang.Symbol;
> > import clojure.lang.Var;
>
> > public class TestSpringLoadClojure  {
>
> >         final static private Symbol CLOJURE_MAIN = Symbol.create
> > ("clojure.main");
> >         final static private Namespace CLOJURE_MAIN_NS =
> > Namespace.findOrCreate(CLOJURE_MAIN);
> >         final static private Var REQUIRE = Var.intern(RT.CLOJURE_NS,
> > Symbol.create("require"));
> >         final static private Var LEGACY_REPL = Var.intern(CLOJURE_MAIN_NS,
> > Symbol.create("legacy-repl"));
> >         final static private Var LEGACY_SCRIPT = Var.intern(CLOJURE_MAIN_NS,
> > Symbol.create("legacy-script"));
> >         final static private Var MAIN = Var.intern(CLOJURE_MAIN_NS,
> > Symbol.create("main"));
>
> >         private static void legacy_script(String[] args) throws Exception {
> >                 REQUIRE.invoke(CLOJURE_MAIN);
> >                 LEGACY_SCRIPT.invoke(RT.seq(args));
> >         }
>
> >         private static void invoke_script(String[] args) throws Exception {
> >                 LEGACY_SCRIPT.invoke(RT.seq(args));
> >         }
>
> >         public static void main(final String [] args) throws Exception {
>
> >                 final String [] scripts  = {  };
> >                 final String [] scripts2 = { "clj/utils/test_use_utils.clj" 
> > };
> >                 legacy_script(scripts);
> >                 Var.intern(Namespace.findOrCreate(Symbol.create("clojure")),
> > Symbol.create("*console*"), "abc");
> >                 invoke_script(scripts2);
>
> >         }
>
> > }
>
> > But I get an error message:
>
> >      [java] java.lang.Exception: Unable to resolve symbol: *console*
> > in this context (test_use_utils.clj:45)
> >      [java]     at org.apache.tools.ant.taskdefs.ExecuteJava.execute
> > (ExecuteJava.java:194)
>
> Nevermind.
>
> (println "-->" clojure/*console*)
>
> if I do this, I get it


Anyone?  Use the Java clojure code directly at all, ever?
--~--~---------~--~----~------------~-------~--~----~
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
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