Getting started with lein-cljsbuild

730 views
Skip to first unread message

Mark Engelberg

unread,
Apr 19, 2012, 12:51:33 AM4/19/12
to clojure
I'm getting ready for my first foray into Clojurescript.  I managed to get all the tools installed under Windows, and can run the repl and compiler from the command line using the instructions found at: https://github.com/clojure/clojurescript/wiki/Quick-Start

So far, so good.  Next, I downloaded lein 1.7.1 and tried to get set up with lein-cljsbuild.

Step 1 is to add the following line to the project.clj file:
  :plugins [[lein-cljsbuild "0.1.8"]]

Next I tried to run lein deps, but got the following error:

C:\temp\cljstest>lein deps
Copying 3 files to C:\temp\cljstest\.lein-plugins
Exception in thread "main" java.lang.NoClassDefFoundError: and
Caused by: java.lang.ClassNotFoundException: and
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: and.  Program will exit.

I do see three files in .lein-plugins, namely commons, fs, and lein-cljsbuild jars.

But when I type:
lein cljsbuild once
from the command line, I am told that no such task exists, so I assume the error prevented the plugin from fully installing?

Any suggestions to get cljsbuild working would be great.  Thanks,

Mark

Mark Engelberg

unread,
Apr 19, 2012, 1:32:11 AM4/19/12
to clojure
I was able to get the plugin working by typing the following at the command-line (rather than using lein deps):
C:\temp\cljstest>lein plugin install lein-cljsbuild 0.1.8

Evan Mezeske

unread,
Apr 19, 2012, 3:03:53 AM4/19/12
to clo...@googlegroups.com
That's great news that you got it to work.  I can't make any sense of the stack trace you're seeing with "lein deps", though, unfortunately.

Other than installation, does the plugin seem to work (e.g. "lein cljsbuild once", etc)?  I haven't tested it under Windows myself, and people have had trouble with it in the past (albeit with older versions of the plugin).

-Evan

Mark Engelberg

unread,
Apr 19, 2012, 3:18:35 AM4/19/12
to clo...@googlegroups.com
Yes, I've only tested "lein cljsbuild once", but it worked just fine once I figured out the alternative way to get the plugin installed.

Mark Engelberg

unread,
Apr 19, 2012, 4:29:19 AM4/19/12
to clo...@googlegroups.com
Unfortunately, "lein trampoline cljsbuild repl-rhino" (and all the trampoline tasks)
generates the same error that I got when I tried to run lein deps.

Chris Perkins

unread,
Apr 19, 2012, 6:31:29 AM4/19/12
to clo...@googlegroups.com
On Thursday, April 19, 2012 3:03:53 AM UTC-4, Evan Mezeske wrote:
That's great news that you got it to work.  I can't make any sense of the stack trace you're seeing with "lein deps", though, unfortunately.

Other than installation, does the plugin seem to work (e.g. "lein cljsbuild once", etc)?  I haven't tested it under Windows myself, and people have had trouble with it in the past (albeit with older versions of the plugin).

On Windows,  "Could not find the main class: and." invariably means that a classpath was not quoted somewhere - the "and" being from "Documents and Settings".

eg: java -cp C:\Documents and Settings\username\.lein\plugins... etc

- Chris

Mark Engelberg

unread,
May 28, 2012, 8:30:40 PM5/28/12
to clo...@googlegroups.com
On Thu, Apr 19, 2012 at 1:29 AM, Mark Engelberg <mark.en...@gmail.com> wrote:
Unfortunately, "lein trampoline cljsbuild repl-rhino" (and all the trampoline tasks)
generates the same error that I got when I tried to run lein deps.

I mentioned last month that I was able to get "lein cljsbuild once" to work, but wasn't able to get "lein trampoline cljsbuild ______" to work.

At first, I suspected that the problem was lein trampoline, and I do think there was a problem with that.  But after changing all environment variables to remove spaces, I seem to be able to use trampoline in other contexts.  Nevertheless, I still can't do something like "lein trampoline cljsbuild repl-rhino" to launch a repl.

I still get the error:
Running Rhino-based ClojureScript REPL.

Exception in thread "main" java.lang.NoClassDefFoundError: and
Caused by: java.lang.ClassNotFoundException: and
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: and.  Program will exit.

Has anyone successfully gotten cljsbuild to launch a repl under Windows?

Thanks,

Mark
 

Ben Mabey

unread,
May 28, 2012, 9:28:22 PM5/28/12
to clo...@googlegroups.com
I actually hit this same problem with lein-cljsbuild the other day but on OSx.  I had ~/Foo Bar Baz/my-project and it was complaining that the Bar class could not be found when I tried to use the repl tasks.  So, I don't think it is strictly a Windows problem.. just one that pops up more in Windows.

-Ben

Evan Mezeske

unread,
May 28, 2012, 9:47:05 PM5/28/12
to clo...@googlegroups.com
This looks like a problem with Leiningen's trampoline feature to me.

I edited my ~/bin/lein script, to insert "echo $TRAMPOLINE" before "exec sh -c "exec $TRAMPOLINE", near the end of the file.  I then copied the lein-cljsbuild advanced example project into a path that contained a space (".../advanced and stuff/...").  When I ran "lein trampoline cljsbuild repl-rhino", I saw the same "java.lang.ClassNotFoundException: and" error.

Looking at the trampoline command that lein printed out, it contains "java -cp <classpath>", where <classpath> is not quoted.  Thus, things break, because I ensured that there was a space in a classpath component.

For reference: $lein -v => "Leiningen 1.7.1 on Java 1.6.0_29 Java HotSpot(TM) 64-Bit Server VM"

Mark Engelberg

unread,
May 28, 2012, 9:47:58 PM5/28/12
to clo...@googlegroups.com
On Mon, May 28, 2012 at 6:28 PM, Ben Mabey <b...@benmabey.com> wrote:
I actually hit this same problem with lein-cljsbuild the other day but on OSx.  I had ~/Foo Bar Baz/my-project and it was complaining that the Bar class could not be found when I tried to use the repl tasks.  So, I don't think it is strictly a Windows problem.. just one that pops up more in Windows.

-Ben



Interesting.  My project is not in a directory with spaces.  The error would indicate that for some reason cljsbuild is looking in my Documents and Settings folder for something, but I have no idea what.

Evan Mezeske

unread,
May 28, 2012, 9:49:17 PM5/28/12
to clo...@googlegroups.com
Also, observe that if the project's path contains a space, "lein trampoline repl" fails as well.

Mark Engelberg

unread,
May 28, 2012, 9:53:40 PM5/28/12
to clo...@googlegroups.com
On Mon, May 28, 2012 at 6:49 PM, Evan Mezeske <emez...@gmail.com> wrote:
Also, observe that if the project's path contains a space, "lein trampoline repl" fails as well.



Right, this is a big part of why I think that lein trampoline was at least part of the culprit.  But by ensuring that the project's path didn't contain a space, and by eliminating all spaces from my environment variables, lein trampoline repl is now working for me, also lein trampoline run (which didn't work before).

Given that "Documents and Settings" can no longer be found in any of my environment variables, any ideas why cljsbuild would be rooting around in there?

Evan Mezeske

unread,
May 28, 2012, 10:10:56 PM5/28/12
to clo...@googlegroups.com
Right, this is a big part of why I think that lein trampoline was at least part of the culprit.  But by ensuring that the project's path didn't contain a space, and by eliminating all spaces from my environment variables, lein trampoline repl is now working for me, also lein trampoline run (which didn't work before).

Given that "Documents and Settings" can no longer be found in any of my environment variables, any ideas why cljsbuild would be rooting around in there?
 
I'm not really sure what environment variables have to do with the problem.  The classpath that is generated by the trampoline task is going to contain a bunch of stuff from your project's :source-path, :extra-classpath-dirs, wherever your maven repository lives, wherever your lein plugins dir is, etc.  Since it's not quoted properly, if any of those paths contain a space, you're hosed.

I would hack your lein script to print out the $TRAMPOLINE command, and see if the -cp argument is quoted properly.  If it's not quoted properly, then I'd look into fixing lein.

It seems like the fix would be fairly simple.  This seems like a good place to start:

Phil Hagelberg

unread,
May 29, 2012, 12:39:44 PM5/29/12
to clo...@googlegroups.com
On Mon, May 28, 2012 at 7:10 PM, Evan Mezeske <emez...@gmail.com> wrote:
> I'm not really sure what environment variables have to do with the problem.

Leiningen used to check the $CLASSPATH variable, but I don't think
anyone had ever used that on purpose; it just caused problems in
practice. Going forward (2.0.0-preview5+) it does not.

> The classpath that is generated by the trampoline task is going to contain
> a bunch of stuff from your project's :source-path, :extra-classpath-dirs,
> wherever your maven repository lives, wherever your lein plugins dir is,
> etc.  Since it's not quoted properly, if any of those paths contain a space,
> you're hosed.

Yeah, started an issue to track this:

https://github.com/technomancy/leiningen/issues/606

Need to make sure indiscriminately applying quoting to each element in
write-trampoline is OK, but if so that should do the trick.

-Phil
Reply all
Reply to author
Forward
0 new messages