clojure.core/import fix

1 view
Skip to first unread message

Tomasz

unread,
Feb 5, 2009, 5:38:26 AM2/5/09
to Clojure
Test case:

---

(add-classpath "file:///home/user/.maven/repository/commons-io/jars/
commons-io-1.4.jar")

(ns import-testcase
(:refer-clojure)
(:import (org.apache.commons.io FileUtils)))

---

Loading code above results in java.lang.ClassNotFoundException. This
is beacuse clojure.core/import uses java.lang.Class#forName(String)
method to load class, which in turn uses classloader that clojure
runtime was started with. Classes added to classpath using
(add-classpath) are not visible.

Shouldn't import handle also classes added to classpath by
add-classpath? If so here's the patch that fixes it (by using
java.lang.Class#forName(String,boolean,ClassLoader) method):

http://groups.google.pl/group/clojure/web/import-fix.diff

If throwing ClassNotFoundException is desirable can someone provide me
with another way to use unqualified classes added to classpath using
add-classpath? Fully qualified class names are visible.

Tomasz

Reply all
Reply to author
Forward
0 new messages