开发者

clojure/lein REPL with jline

开发者 https://www.devze.com 2023-01-06 12:31 出处:网络
For some reason I can\'t get clojure REPL working with jline, what i did was git clone the clojure repository off github then run ant to build it, then i download jline-0.9.94.jar to the directory wit

For some reason I can't get clojure REPL working with jline, what i did was git clone the clojure repository off github then run ant to build it, then i download jline-0.9.94.jar to the directory with clojure.jar, then run the following command:

java -cp jline-0.9.94.jar:clojure.jar jline.ConsoleRunner clojure.main

And get the following errors:

    Exception in thread "main" java.lang.ClassNotFoundException: clojure.main
 at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:317)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
 at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:375)
 at java.lang.Class.forName0(Native Method)
 at java.lang.Class.forName(开发者_JS百科Class.java:164)
 at jline.ConsoleRunner.main(Unknown Source)

Here are the files in my current directory:

vvshs-macbook-2:clojure vvsh$ ls
build.xml                                 clojure-sources-1.2.0-master-SNAPSHOT.jar epl-v10.html                              src
classes                                   clojure-sources.jar                       jline-0.9.94.jar                          test
clojure-1.2.0-master-SNAPSHOT.jar         clojure.iml                               pom-template.xml
clojure-slim-1.2.0-master-SNAPSHOT.jar    clojure.jar                               pom.xml
clojure-slim.jar                          doc                                       readme.txt
vvshs-macbook-2:clojure vvsh$ 

I got the same error on clojure 1.1 and lein repl(it seems lein maintain its own version of clojure).

By the way, this is on mac ox 10.5.8

java version "1.5.0_24"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_24-b02-357-9M3165)
Java HotSpot(TM) Client VM (build 1.5.0_24-149, mixed mode, sharing)

Anybody know what's wrong and how to fix it? As I really want to get lein repl working to start a project.


I solved the same problem today by removing a redundant jline*.jar from /Library/Java/Extensions, leaving just one jline installation in CLASSPATH.

Longer explanation: I was trying to build labrepl, which installs all its dependencies in subdirectory lib, but I had previously set up jline by copying the .jar file to /Library/Java/Extensions. Apparently, java.lang.ClassLoader couldn't handle two installations of jline, and as long as there were ones available in two places, the command line starting a Clojure REPL would fail finding the latter one of classes jline.ConsoleRunner and clojure.main, depending on the order they were given to the java command.

I hope this helps.


see my alternative instructions for install on my fork:

http://github.com/jedschneider/leiningen

I sent a pull request to update the readme, but didn't get a response on it. once you have lein installed, you can put the bin/leiningen.sh in your ~/bin and call it anywhere. i put a shortcut on my .bash_profile

alias lein="~/bin/leiningen.sh"

and then call lein repl to launch a shell

also checkout the labrepl which is a great learning tool.

http://github.com/relevance/labrepl


Your java ... command looks fine, I'd double check if all the jars are where you think they should be (and that they are the jars you think they are, i.e. clojure.jar is actually the one you built locally and not some super-outdated one).

If you want to use Leiningen for lein repl, that's possible too. Note that it isn't accurate to say that it "maintains its own version of Clojure"; Leiningen is a build tool, used as part of a project-oriented workflow, and the separate Clojure jars are project-specific. To create a sample project to play around in, say lein new foo someplace convenient. Then you'll need to cd foo, get your Clojure & contrib jars with lein deps (the project.clj skeleton provided by lein new already contains entries for both) and start a REPL with lein repl.

Finally, you could use the new cljr project; it has a comprehensive README which should get you started in no time, and with it you'll be able to say cljr repl to get a Clojure REPL anywhere, without the need to create a "project".


I met the same problem. jline.ConsoleRunner (at least about jline-0.9.5 which I use) seems not to be able to find class files in the path added to class search paths from -cp option of 'java' command. It means it can't find neither classes in your current directory. I solved this by copying clojure.main under /Library/Java/Extensions/ too.

0

精彩评论

暂无评论...
验证码 换一张
取 消