passing clojure functions into a java program.
I can't seem to figure out why java can't find the clojure class in the following example, where f is a clojure function (defn cascading-function [f] (proxy [BaseOperation Function] [(Integer. 1) (Fields. (into-array Comparable [line]))] (operate [flowProcess functionCall] (let [clojureData (. (Tuple. (. (. functionCall getArguments) getTuple)) getString 1) result (hadoop-function f clojureData) resultTuple (Tuple.)] (. resultTuple add result) (. (. functionCall getOutputCollector) add resultTuple) cascading function returns a java object that implements Function (from the cascading framework) and extends BaseOperation, and it implements the operate method. The error that I am seeing is a ClassNotFoundException for whatever I pass in as f. For some more context, I am trying to wrap the cascading framework in clojure, (www.cascading.org) The internal driver/framework code is in Java, and I am using clojure to wrap the user hooks for defining operations and making jobs. This wrapping mainly involves tedious creation of objects, one of the objects is this Function object, and I am trying to proxy Function and make it close over (closure) clojure functions so that I can define the actual logic in a nice (clojure) way. (If i implement the Function interface as an object in Java, everything seems to run fine) Java (framework code) - Clojure (wrapper over making jobs) - Java (an operation, implements Function interface) (defn cascading-function [] (FunctionSample.)) what I want is Java (framework code) - Clojure (wrapper over making jobs) - Clojure (operation) but the final part is not working so well. cascading-function is called by clojure code which wraps/builds up objects for use by Java/cascading framework. Does anyone know what I might be doing wrong? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: passing clojure functions into a java program.
Hi Stephen, Thanks for the note. Yea that first post was kind of unwieldy. hadoop-function takes in f and data, and does some preprocessing before applying f to the processed data. (I tried it by just using f directly and taking hadoop-function out, and same thing happens) One of the problems that I am having is that I'm having a hard time to reproduce this in a smaller manner. Everything works out fine in the repl, but when the framework/runtime starts up, it throws a ClassNotFoundException It's trying to find:cascading$cascading_function__44$fn__46 When I look in my target directory/exploded jar, it has this cascading$cascading_function__38$fn__40.class On Jun 21, 8:36 pm, Stephen C. Gilardi squee...@mac.com wrote: On Jun 21, 2009, at 11:07 PM, timshawn wrote: I can't seem to figure out why java can't find the clojure class in the following example, where f is a clojure function (defn cascading-function [f] (proxy [BaseOperation Function] [(Integer. 1) (Fields. (into-array Comparable [line]))] (operate [flowProcess functionCall] (let [clojureData (. (Tuple. (. (. functionCall getArguments) getTuple)) getString 1) result (hadoop-function f clojureData) resultTuple (Tuple.)] (. resultTuple add result) (. (. functionCall getOutputCollector) add resultTuple) cascading function returns a java object that implements Function (from the cascading framework) and extends BaseOperation, and it implements the operate method. The error that I am seeing is a ClassNotFoundException for whatever I pass in as f. The only place f appears is as the argument to hadoop-function. What's that expecting for arguments? In general if you can come up with a small runnable example that shows the problem (with as few dependencies as possible), that's the easiest way for interested folks to help. Showing the relevant portion of the stack trace for the exception is also likely to be helpful. You can get the stack trace for the most recent exception caught by the REPL with (.printStackTrace *e) (see also clojure.contrib.repl-utils for convenience functions around that.) --Steve smime.p7s 3KViewDownload --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Making a jar where the main class in manifest is from gen-class
Thanks! I was bitten by the underscore and dashes thing in the package name/filesystem. This example fortunately had that to show me the way to do it. Thanks for your help. On Jun 19, 10:42 am, Stephen C. Gilardi squee...@mac.com wrote: On Jun 19, 2009, at 1:02 PM, timshawn wrote: Hello clojure developers, I had a question regarding jar-ring up clojure generated source using gen-class. When I do a gen-class, and say either :main is true, or add a -main method, the class file that gets generated always has a random prefix. One important need filled by gen-class is exactly this case: you need a class with a name you can specify completely and use elsewhere. I need to enter the Main class in a jar's Manifest, and was wondering how you guys have done it. There's an example at clojure.contrib.repl_ln.clj. It uses just (:gen- class) (no options) in its ns declaration: (ns ... clojure.contrib.repl-ln (:gen-class) ...) (defn- -main Main entry point, starts a repl enters the user namespace and processes command line args. [ args] (repl :init (fn [] (println Clojure (clojure-version)) (in-ns 'user) (process-command-line args (this could also have been defn rather than defn- and would behave the same regarding being callable from Java) When compiled, this produces the class file: clojure/contrib/repl_ln.class You can see it in clojure.contrib.jar (either using a tool that can display its contents directly or bar unjarring it: jar xvf clojure.contrib.jar) If the example above doesn't lead you to a solution, please post more particulars and a simplified example that shows the problem you're seeing. --Steve smime.p7s 3KViewDownload --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Making a jar where the main class in manifest is from gen-class
Hello clojure developers, I had a question regarding jar-ring up clojure generated source using gen-class. When I do a gen-class, and say either :main is true, or add a -main method, the class file that gets generated always has a random prefix. I need to enter the Main class in a jar's Manifest, and was wondering how you guys have done it. Can I somehow control the name of the generated class of the main function? Or is there some other way? Thanks, Tim --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---