Getting started with La Clojure

From IntelliJ-Wiki

Jump to: navigation, search

This guide takes you step by step through creating a La Clojure project using IntelliJ IDEA, La Clojure and Leiningen plugins.

Contents

Prerequisites

  • You are working with IntelliJ IDEA Community Edition or Ultimate Edition version 12 or higher.
  • Leiningen is installed on your computer.

Creating a Leiningen project

Outside of IntelliJ IDEA, perform the following lein command to create a new lein project:

lein new foobar

The new lein project foobar is created under the directory C:\lein_project:

File:lein_project.png

Open for editing the file project.clj, and specify the desired version of Clojure:

File:clojure_version.png

Installing La Clojure and Leiningen plugins

1. Launch IntelliJ IDEA. To do that, just double-click the desktop shortcut icon File:ij_shortcut.png, or double-click idea.exe or idea.bat under the bin directory of your IntelliJ IDEA installation.

IntelliJ IDEA starts and displays the Welcome screen, where you click the link Configure:

File:Welcome_screen_Idea12.png

2. In the Configure page, click the link Plugins:

File:Welcome_screen_Idea12_plugins.png

3. Note that La Clojure and Leiningen plugins are not bundled with IntelliJ IDEA. They should be downloaded from the Jetbrains repository and installed. This is how it's done:

In the Plugins dialog box, click the button Browse repositories, to show the list of repository plugins.

Find the La Clojure plugin, download and install it:

File:install_plugin.png

Then, same way, download and install the Leiningen plugin.

When both plugins are installed, they appear in the list of available plugins. When you apply changes, IntelliJ IDEA prompts to restart, for the newly installed plugins to take effect:

File:restart.png

Opening project in IntelliJ IDEA

On the Welcome screen, click Open Project:

File:open_project.png

Since La Clojure plugin has been installed, IntelliJ IDEA now recognizes the La Clojure projects:

File:open_project_laclojure.png

On clicking OK, IntelliJ IDEA opens the new project, and shows its structure in the Project tool window:

File:project_in_idea.png

Defining JDK

Try to run core.clj, and you will immediately get an error message: No jdk for module 'foobar'. So let us define a suitable JDK for the project.

To do that, on the main toolbar click the Project Structure button :

File:project_structure_in_idea.png

The Project Structure dialog opens the Project page, with the missing JDK. Click New, on the pop-up menu, choose JDK, and then select the preferred JDK on your file system:

File:set_up_jdk.png

Note that JDK you've just added as the project JDK, appears in the SDKs page of the Project Structure dialog. Open the SDKs page to explore the constituents of the selected JDK:

File:jdk_jars.png

Exploring module dependencies

This step is performed just for making sure that everything is OK. In the Project Structure dialog, open the Modules page, and click the tab Dependencies.

You see that Leiningen La Clojure version 1.5.1 is added as the module dependency:

File:explore_module_dependencies.png

You can also observe this library in the tree view of the external libraries in the Project tool window.

Using La Clojure console

As the La Clojure plugin is installed, it adds new items to the IntelliJ IDEA UI. In particular, under the Tools menu, you can find the command that lets you launch the REPL console:

File:start_console.png

The console features undo/redo (Ctrl+Z/Ctrl+Shift+Z), code completion (Ctrl+Space) and history of entered commands (Up/Down):

File:run_console.png

Creating and running La Clojure code

Let us create a source file with some La Clojure code. To do that, select foobar package, and choose New | File on the context menu. Specify the file name and extension: let it be, say, hw.clj. As you see, IntellyJ IDEA immediately opens the new file for editing, and marks it with the dedicated icon.

Type the following code in the created file:

  (defn hello-world []
 (println "Hello world"))

Mind the code completion and syntax and error highlighting in the La Clojure code!

Next, on the Tools menu, point to Clojure REPL, and then choose Load file to REPL. The new file is loaded into the interactive console and immediately run:

File:load_in_console.png

You can also select this code in the editor, and choose Run selected text in REPL:

File:load_in_console1.png

Personal tools