views:

290

answers:

2

I have a problem with the Enclojure REPL and using clojure modules from it. The Load/Change REPL to file/ns works fine with an isolated clojure file, but breaks with a file which has references to another clojure file which I try to use from my project.

Here are the exact steps:

  • Create a new project.
  • Create a clojure module foobar.clj (namespace com.acme.foobar)
  • Define a function which returns a value in foobar.clj:

    (ns com.acme.foobar (:use com.acme.othermodule))

    (defn myfunc1 [] "a")

  • Open a Netbeans IDE REPL

  • From foobar.clj's context menu select:

    • Change REPL to file/ns
    • Load
  • From REPL call the (myfunc1) function. This works just fine:

    com.acme.foobar=> (myfunc1) "a"

The problems start when when I try to refer to other files from foobar. Here's what I do:

  • Create a new clojure module othermodule.clj

    (ns com.acme.othermodule)

    (defn fromothermodule [] "b")

  • Now try to call this from foobar.clj:

    (defn myfunc2 [] (fromothermodule))

  • From othermodule.clj's context menu I select:

    • Change REPL to file/ns
    • Load

To make the REPL realize that there is new module it should be able to run.

  • I do same things things to foobar.clj which now refers to othermodule.clj, but I get:

CompilerException java.io.FileNotFoundException: Could not locate com/acme/othermodule__init.class or com/acme/othermodule.clj on classpath: (NO_SOURCE_FILE:50) com.acme.foobar=>

This error message comes from both "Change REPL to file/ns" and "Load"

What am I missing? Should I do some other tricks to make this happen? Even the desperate measure of Run->Clean and Build the main project doesn't help (that would of course make the REPL business pretty painful anyway).

I am using NetBeans 6.7.1 and enclojure-plugin-2009-11-3.nbm.

+1  A: 

My first recommendation is to move from NetBeans/Enclojure to IDEA/La Clojure. JetBrains recently created an open source version of their IDE, and the Clojure plugin works fine in it. Since discovering this, I ditched NetBeans and Enclojure. I find La Clojure a pleasure to work in, but of course your mileage may vary.

Back from when I did this in NetBeans, I seem to remember Enclojure source code resides in a subdirectory called "lib". I think I solved a similar problem by fiddling with directory prefixes on the name of the file to load. Probably something like "../lib/YourName". I managed this by trial and error, so I can't relate the exact rules and syntax.

Two things that might help:

  • You can run something like (println (System/getProperty "java.user.dir")) to find out where Clojure thinks it's executing from.

  • You could start, as I did, with using an absolute path until you find your way to the correct directory name. Something like "/home/carl/NetbeansProjects/MyProject/lib/myfile.clj" .

Carl Smotricz
Thanks! IDEA didn't even cross my mind even though I installed it on my work machine after it was open sourced to check it out. I'll definitely try it.I'll try your NetBeans tricks also, although the usability suffers considerably if I can't use the "context-menu-over-file-load" option.
auramo
This is embarrassing: It turns out IDEA is the one with the "lib" directory. Heh, I'm glad you got the right answer anyway.
Carl Smotricz
+2  A: 

Got the right solution from Eric Thorsen in the google group:

There are three ways to create the REPL from window-menu. Don't use any of those, instead right click on the Project and "Start Project REPL". Now the paths are set up accordingly.

auramo