add-classpath erroring out, post r1100...

5 views
Skip to first unread message

Scott Fleckenstein

unread,
Nov 17, 2008, 1:00:43 PM11/17/08
to Clojure
Hi All,

I've run into a bug since upgrading past revision 1100, specifically
around adding to the classpath at runtime using add-classpath. I've
attached a test case here: http://s3.amazonaws.com/nullstyle/precompile-bug.tar.gz

That file has three versions of clojure (r1100, r1101, r1106) and
web.clj, a sample app that loads jetty and starts a simple web
server. You can use run.sh in that same tar to run each revision, one
after the other, to illustrate the breakage.

Basically, after adding a jar to the classpath, when importing a class
file from that jar I get a ClassNotFoundException thrown. I don't
have enough java experience to know what would cause this problem.
Things work as expected on revision 1100.

Does anyone know what would cause this? I'd be happy to put in the
time to help debug and fix this, but I'm at a loss for where next to
go.

Thanks,
Scott Fleckenstein

Rich Hickey

unread,
Nov 17, 2008, 1:32:08 PM11/17/08
to Clojure
Such use of add-classpath is discouraged. The only reason for add-
classpath is to let you pull in something if you've started up the
repl without it. It shouldn't be a permanent part of any application
design. In your case, you can get the local Jetty jars in the mix by
supplying an extension dirs directive (-Djava.ext.dirs=) on the
command line:

java -Djava.ext.dirs=. -cp clojure-r1106.jar clojure.lang.Script
web.clj

All three revisions work with this change, and you can remove the add-
classpath calls.

The change that caused this is that now .class files for Clojure fn
classes can be found and loaded by a classloader higher up in the
chain, one which can't see the effects of add-classpath.

I'm going to deprecate add-classpath because people consistently use
it to avoid the standard classpath-setting mechanisms, at least until
I can figure out a way to coordinate it with the standard classloader.

Rich

Scott Fleckenstein

unread,
Nov 17, 2008, 2:01:25 PM11/17/08
to Clojure
Thanks Rich,

While I understand the desire to stick with java conventions when it
comes to adding to the classpath, it is too bad because it takes away
from the 'explorability' you get with a Repl. I've gotten into the
habit of just dumping jars into my scratch folder and tooling away on
my running Repl to learn an API. Oh well, I can tweak my workflow :)

-Scott

Phil Jordan

unread,
Nov 17, 2008, 2:03:28 PM11/17/08
to clo...@googlegroups.com
Rich Hickey wrote:
> I'm going to deprecate add-classpath because people consistently use
> it to avoid the standard classpath-setting mechanisms, at least until
> I can figure out a way to coordinate it with the standard classloader.

You could make it a thread-local binding within the repl and unbind it
when gets (load )ed from file. That'll show 'em! ;)

~phil

Reply all
Reply to author
Forward
0 new messages