Pre-requisites
- Java 6 (for running Eclipse, you can still use Java 5 for your projects)
Install Eclipse
(If you do not have Eclipse installed, or you want to make isolated tests of the Clojure plugin for Eclipse)
- Grab a recent version of eclipse with Java support (embedding JDT), e.g. the “Eclipse IDE for java developers” from the download pagethe Eclipse ZIP file from http://www.eclipse.org/downloads . If you do not know which "package" to get, pick the "Eclipse IDE for Java Developers" one since it ships out of the box with Git support
- Unzip it somewhere. The executable is eclipse (linux) or eclipse.exe (windows) located in the eclipse/ directory created by the unzip operation
- The first time Eclipse is run, it will ask you for a location on your disk where eclipse will put its metadata and will create new projects by default.
Install Counterclockwise (the Clojure plugin for Eclipse)
(Counterclockwise, CCW for short, is the Clojure plugin for Eclipse)
You install it via the “software update center”, that is:
- Menu Help > Install new software…
- Paste the following Counterclockwise url in the “Work with:” textbox: http://ccw.cgrand.net/updatesite/ , Hit Enter
- Select counterclockwise, verify the “Contact all update sites during …” chekbox is checked, click next, accept licence, etc., restart Eclipse
- Go to menu Window > Reset Perspective ... this will reset the way the views are layout, and also and and place correctly the views contributed by counterclockwise (for now - July 2010 -, Counterclockwise (the Namespace Browser viewerview, placed "behind" the code outline view)
Test the install
Create and run a simple Clojure project ("Hello
...
Betty")
- Open the Java perspective
- :
- Window > Open Perspective > Java (a perspective is a predefined layout of views, suitable for a particular type of development)
- Create a Clojure project
- With Leiningen Project Wizard: File > New > Leiningen Project... > Clojure Project, name it firstClojureProject
- Create a Clojure source code file in the src/ directory: File > New > File, twist down firstClojureProject in the file creation wizard and select "src" as the ** the parent folder, and name the file helloworld.clj
- Type code in it to define a function: myproject
- The project is created using the "default" Leiningen Template, which creates a Clojure project with a predefined "myproject.core" namespace in src/myproject/core.clj
- Add a function definition to myproject.core:
- Open src/myproject/core.clj, add the following at the end: (defn hello [who] (str "Hello " who " !")) (leave the (ns helloworld) call at the beginning of the file), save the file
- Run it: Select the firstClojureProject>src>helloworld.clj file, then menu Run > Run as > Clojure REPL. this evaluates the code and starts a REPLthe project:
- With file src/myproject/core.clj open, Hit Ctrl+Alt+S (Cmd+Alt+S on MacOS). This sends the whole file's code to the REPL (and also takes care of starting a REPL for the project if none is currently started)
- Switch to the REPL in the namespace of your file:
- Hit Ctrl+Alt+N (Cmd+Alt+N on MacOS). Alternatively, just click on the bottom of the REPL inside the "text input area"
Call your function (Hit
Ctrl+Enter to send the expression
to the REPL serverif the cursor is at the end, or hit Ctrl+Enter / Cmd+Enter if the cursor is not at the end of the text):
No Format > 1:1 helloworld=> (hello "Betty") [Ctrl+Enter] > "Hello Betty !"
Installing and running the labrepl environment for learning Clojure
- Install EGit, Git support in Eclipse (optional if you already use another git client)
- You install it via the “software update center”, that is:
- Menu Help > Install new software…
- Paste the following EGit url in the “Work with:” textbox: http://download.eclipse.org/egit/updates
- Hit Enter
- Select “Eclipse EGit feature”, verify the “Contact all update sites during …” chekbox is checked, click next, accept licence, etc., restart Eclipse
- Install m2e, Maven support in Eclipse
- You install it via the “software update center”, that is:
- Menu Help > Install new software…
- Paste the following maven2eclipse (m2e) url in the “Work with:” textbox: http://m2eclipse.sonatype.org/sites/m2e
- Hit Enter
- Select Maven Integration for Eclipse, verify the “Contact all update sites during …” chekbox is checked, click next, accept licence, etc., restart Eclipse
- Grab labrepl from git via EGit
- Menu File > Import … > Git > Git Repository ; Hit Next
- URI: git://github.com/relevance/labrepl.git ; Hit Next ; Hit Next ; Uncheck "Import Existing Projects"; Hit Finish
- Import the maven project into Eclipse
- Menu File > Import ... > Maven > Existing Maven Projects ; Hit Next
- Choose root directory (wherever you dropped the labrepl in the previous step); Hit Finish
- Wait while Maven does a bunch of stuff in the background
- Enable Clojure Support
- Right-click the "labrepl" project in Package Explorer and choose "Enable/disable Clojure language support"
- Run the labrepl
- Right click on project “labrepl” in the Package Explorer
- Run as > Clojure REPL
In the REPL Console:
No Format (require 'labrepl) (labrepl/-main)[Ctrl+Enter]- Browse to localhost:8080
- Enjoy the labs!