I wrote something similar to what you are asking about. My code does not import java class files but calls 'use' on clojure files that live in the clojure-contrib.jar file. I load this when I start the REPL only.
(defn name-to-symbol [lib-name] "Converts the lib-name to a symbol" (-> lib-name (.replaceFirst ".clj$" "") (.replaceAll "_" "-") (.replaceAll "/" ".") (symbol))) (defn contrib-ns [jar] "Returns a seq of symbols from the clojure.contrib package, is not recursive" (for [f (map #(.getName %) (enumeration-seq (.entries (java.util.zip.ZipFile. jar)))) :when (and (.endsWith f "clj") (= 3 (count (.split f "/"))) (not (or (.endsWith f "test_clojure.clj") (.endsWith f "test_contrib.clj"))))] (name-to-symbol f))) ;sets the variable to the colure-contrib.jar path, otherwise nil (def contrib-jar (if-let [url (.getResource (ClassLoader/getSystemClassLoader) "clojure-contrib.jar")] (.getFile url))) (defn use-contribs [] "Calls the use function on every clj file in the clojure.contrib package. Not every clj file can be loaded because of function name clashes with the core." (if contrib-jar (println (str "use " (reduce (fn [ret n] (try (use n) (conj ret n) (catch Exception _ ret))) [] (contrib-ns contrib-jar)))))) On Fri, Feb 20, 2009 at 10:48 PM, Jason Wolfe <jawo...@berkeley.edu> wrote: > > I have a horrible hack to do this, which uses even more appalling code > than [2] ripped off from a different forum, but which (in my limited > experience) seems to work OK. I'll email it to you privately, and to > anyone else who wants to use it (just ask). > > -Jason > > On Feb 20, 9:33 pm, Brian Carper <briancar...@gmail.com> wrote: > > One could argue that wildcard imports in Java (import package.*) are > > evil, pollute your namespaces, create potential naming conflicts, > > etc. One would probably be correct. > > > > One could also argue that having to manually type a list of dozens of > > classnames is pretty tedious, especially if all you want to do is goof > > off at a REPL for a few minutes. e.g. I wanted to run some SWT > > snippets [1], and to import all the necessary SWT classes into Clojure > > can be a bit of a pain. > > > > I found this somewhat appalling bit of code [2] which I can use to get > > a list of all the classnames in some package and then import them all > > that way. There are all kinds of ways that code can fail though. > > Does anyone else have a way that they routinely import lots and lots > > of Java classes at once? I don't care how dirty a hack it is, I'm not > > going to do this in production code. I only want to save my fingers a > > bit of typing. > > > > I know this probably isn't planned [3] for Clojure, just looking for > > the best workaround. > > > > [1]:http://www.eclipse.org/swt/snippets/ > > [2]:http://forums.sun.com/thread.jspa?threadID=341935&start=30&tstart=0 > > [3]: > http://groups.google.com/group/clojure/browse_thread/thread/c65e19d51... > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---