Getting started with open source Clojure projects

161 views
Skip to first unread message

Daniel

unread,
Mar 29, 2010, 11:39:13 PM3/29/10
to Clojure
If this is a dumb question, let me apologize in advance. The thing is,
I've been trying to learn Clojure in my spare time, and, following the
advice of several Clojure blogs, started by reading Halloway's book
and playing around a bit at the REPL, which is all well and good, but
now I'm ready to tackle something a little bigger. The project that
interests me most is James Reeve's Compojure, so I cloned the
repository with the intention of loading the source files into the
REPL and testing out some of the functions to get an idea of how it
works internally. The first hurdle was getting all the dependent
classes on the classpath, which I did by adding them one by one to
the .clojure file (I'm using a script that concatenates the contents
of .clojure to the classpath before launching the REPL). So far, so
good. However, when I try to load core.clj from the REPL, it complains
about not being able to find "compojure/response.clj" or its
equivalent class. And it does this even if I load response.clj first,
then try to load core.clj.

So here are my questions:

Am I going about this the wrong way? Is there an easier way to explore
existing open-source projects? I
Is there a less cumbersome way to get a load of files on the classpath
than manually editing the .clojure file?
How do I tell the REPL where to find response.clj so that core.clj
will load?

Any other advice will be much appreciated as well.

Thanks,

Daniel

Mark J. Reed

unread,
Mar 30, 2010, 8:55:04 AM3/30/10
to clo...@googlegroups.com
On Mon, Mar 29, 2010 at 11:39 PM, Daniel <cotter...@gmail.com> wrote:
> Is there a less cumbersome way to get a load of files on the classpath
> than manually editing the .clojure file?

Well, I have a ~/lib/clojure directory and a clj script that
automatically puts that directory and all .jar's in it on the
classpath. Linux version:

#!/bin/bash
: "${CLOJURE_LIB:=${HOME}/lib/clojure}"
export CLASSPATH="${CLASSPATH:+$CLASSPATH:}$HOME/lib/java/clojure.jar:$CLOJURE_LIB"
if [ -d "$CLOJURE_LIB" ]; then
for f in "$CLOJURE_LIB"/*.jar; do
if [ -r "$f" ]; then
CLASSPATH="$CLASSPATH:$f"
fi
done
fi
rlwrap java clojure.main "$@"


The actual java invocation can of course be replaced to e.g. use JLine
instead of rlwrap; I use the latter because JLine doesn't seem to have
a vi mode. (Yes, I know, vi user in a Lispy language - heretical!)

--
Mark J. Reed <mark...@gmail.com>

Alex Osborne

unread,
Mar 30, 2010, 9:45:06 AM3/30/10
to clo...@googlegroups.com
Daniel <cotter...@gmail.com> writes:

> Am I going about this the wrong way? Is there an easier way to explore
> existing open-source projects? I

Try this for any leiningen project (check for the existence of a
project.clj file). I'm assuming you're using a unixy operating system.

First and once-off, install leiningen:

wget http://github.com/technomancy/leiningen/raw/stable/bin/lein
chmod a+x lein
./lein self-install

Clone target project (in this case Compojure):

git clone git://github.com/weavejester/compojure.git
cd compojure

Ask Lein to download Compojure's dependencies (this includes Clojure,
you don't need to it install it manually):

../lein deps

Fire up a repl:

../lein repl

Clojure 1.1.0
user=> (use 'compojure.core)
nil

Alternatively if you're using Java 6 you can start the REPL without any
wrapper script pretty easily. I prefer to do it this way as it makes it
obvious what the classpath is and allows tweaking the JVM options (for
example increasing the memory limit with -Xmx256m).

java -cp 'lib/*:classes:src' clojure.main

Clojure 1.1.0
user=> (use 'compojure.core)
nil

> Is there a less cumbersome way to get a load of files on the classpath
> than manually editing the .clojure file?

Note the wildcard 'lib/*' notation I used above. This was added in Java
6. Be aware that it has to be some/directory/* not *.jar, foo* or any
other variation. Put it in single quotes to make sure your shell
doesn't try and expand it. It'll add any jar files found in the
directory to the classpath.

Hope that helps.

Alex

Kevin

unread,
Mar 30, 2010, 9:45:20 AM3/30/10
to clo...@googlegroups.com
> So here are my questions:
>
> Am I going about this the wrong way? Is there an easier way
> to explore existing open-source projects? I Is there a less
> cumbersome way to get a load of files on the classpath than
> manually editing the .clojure file? How do I tell the REPL
> where to find response.clj so that core.clj will load?

For Compojure I think you need also Ring: http://github.com/mmcgrana/ring
(also a mailing list here: http://groups.google.com/group/ring-clojure)

There's been a lot of activity there recently, various projects
refactoring in terms of each other, and that seems to be where
they're ending up. I don't know too much about it, but I did run
through the code and examples just yesterday.

The other thing is: leiningen. http://github.com/technomancy/leiningen
A lot of projects are using it, and it's dead simple dependency management.
Download the project, look for the project.clj file, run 'lein deps'
in that directory, and you get all needed dependency jars loaded into
a 'lib' subdirectory.

cheers,
Kevin Kelley

Stuart Sierra

unread,
Mar 30, 2010, 9:45:46 AM3/30/10
to Clojure
Take a look at the dependency management tools. Most open-source
Clojure projects use either Maven and Leiningen. Both use the same
dependency model and provide similar capabilities for starting a REPL
with the classpath configured automatically.

-SS

Meikel Brandmeyer

unread,
Mar 30, 2010, 10:26:51 AM3/30/10
to Clojure
Hi,

On Mar 30, 3:45 pm, Stuart Sierra <the.stuart.sie...@gmail.com> wrote:

> Take a look at the dependency management tools.  Most open-source
> Clojure projects use either Maven and Leiningen.  Both use the same
> dependency model and provide similar capabilities for starting a REPL
> with the classpath configured automatically.

There are also gradle and ant combined with Ivy as possible helpers.
They also build on the maven repositories. So they should work fine,
too.

Sincerely
Meikel

Matt

unread,
Mar 30, 2010, 8:50:17 PM3/30/10
to Clojure
If you're not stuck on using Compojure, you can try Conjure which will
includes all of the dependencies in the jar.

To start a hello world app:

1. Download conjure.jar from: http://github.com/macourtney/Conjure/downloads
2. java -jar conjure.jar hello_world
3. cd hello_world
4. ./run.sh script/server.clj
5. Point your browser at http://localhost:8080/
6. Profit!

There is a tutorial for Conjure at: http://wiki.github.com/macourtney/Conjure/hello-world-tutorial-2

-Matt Courtney

Daniel

unread,
Mar 30, 2010, 10:26:19 PM3/30/10
to Clojure
Thanks for all the quick replies. I should've mentioned that I'm
already using leiningen, so the problem isn't so much getting the
dependencies and building the application as it is figuring out a way
to get inside the code and play with it a bit. I'd like to be able to
load the source files, execute member functions, and just get a feel
for what's going on internally. What sort of method do you all use for
exploring open source projects? Do you just read the source code, or
do you load it and test it out?

Thanks,

Daniel

On Mar 30, 6:50 pm, Matt <macourt...@gmail.com> wrote:
> If you're not stuck on using Compojure, you can try Conjure which will
> includes all of the dependencies in the jar.
>
> To start a hello world app:
>
> 1. Download conjure.jar from:http://github.com/macourtney/Conjure/downloads
> 2. java -jar conjure.jar hello_world
> 3. cd hello_world
> 4. ./run.sh script/server.clj

> 5. Point your browser athttp://localhost:8080/

David Nolen

unread,
Mar 31, 2010, 9:10:57 AM3/31/10
to clo...@googlegroups.com
On Tue, Mar 30, 2010 at 10:26 PM, Daniel <cotter...@gmail.com> wrote:
Thanks for all the quick replies. I should've mentioned that I'm
already using leiningen, so the problem isn't so much getting the
dependencies and building the application as it is figuring out a way
to get inside the code and play with it a bit. I'd like to be able to
load the source files, execute member functions, and just get a feel
for what's going on internally. What sort of method do you all use for
exploring open source projects? Do you just read the source code, or
do you load it and test it out?

From the library's top level directory you should be able to type:

lein repl

and be able to play around.

If you want integration with an IDE or text editor you might want to add lein-swank as a dev-dependency to the library's project.clj.

A new trick that I just learned is that "lein install" will put the library into your local maven repository so you can play around with it easily in your own projects. It's also a simple way to help test other people's projects (like swank-clojure).

David


Reply all
Reply to author
Forward
0 new messages