250 lines
17 KiB
HTML
250 lines
17 KiB
HTML
<!DOCTYPE html>
|
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
|
<head>
|
|
<meta charset="utf-8"/>
|
|
<title>Clojure Guides: Starting with Eclipse and Counterclockwise For Clojure Development</title>
|
|
|
|
|
|
<meta name="description" content="This guide covers:">
|
|
|
|
<meta property="og:description" content="This guide covers:">
|
|
|
|
<meta property="og:url" content="https://clojure-doc.github.io/articles/tutorials/eclipse/" />
|
|
<meta property="og:title" content="Starting with Eclipse and Counterclockwise For Clojure Development" />
|
|
<meta property="og:type" content="article" />
|
|
|
|
<link rel="canonical" href="https://clojure-doc.github.io/articles/tutorials/eclipse/">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<link href="https://fonts.googleapis.com/css?family=Alegreya:400italic,700italic,400,700" rel="stylesheet"
|
|
type="text/css">
|
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css">
|
|
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/styles/default.min.css">
|
|
<link href="../../../css/screen.css" rel="stylesheet" type="text/css" />
|
|
</head>
|
|
<body>
|
|
|
|
|
|
<nav class="navbar navbar-default">
|
|
<div class="container">
|
|
<div class="navbar-header">
|
|
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
|
|
<span class="sr-only">Toggle navigation</span>
|
|
<span class="icon-bar"></span>
|
|
<span class="icon-bar"></span>
|
|
<span class="icon-bar"></span>
|
|
</button>
|
|
<a class="navbar-brand" href="../../../index.html">Clojure Guides</a>
|
|
</div>
|
|
<div id="navbar" class="navbar-collapse collapse">
|
|
<ul class="nav navbar-nav navbar-right">
|
|
<li ><a href="../../../index.html">Home</a></li>
|
|
<li><a href="https://github.com/clojure-doc/clojure-doc.github.io">Contribute</a></li>
|
|
</ul>
|
|
</div><!--/.nav-collapse -->
|
|
</div><!--/.container-fluid -->
|
|
</nav>
|
|
|
|
|
|
<div class="container">
|
|
|
|
|
|
<div class="row">
|
|
<div class="col-lg-9">
|
|
<div id="content">
|
|
|
|
<div id="custom-page">
|
|
<div id="page-header">
|
|
<h2>Starting with Eclipse and Counterclockwise For Clojure Development</h2>
|
|
</div>
|
|
|
|
<p>This guide covers:</p><ul><li>Installing Eclipse</li><li>Installing Counterclockwise, the Clojure plugin for Eclipse</li><li>Creating a sample project</li></ul><p>This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 Unported License</a>
|
|
(including images & stylesheets). The source is available <a href="https://github.com/clojure-doc/clojure-doc.github.io">on Github</a>.</p><h2 id="what-version-of-clojure-does-this-guide-cover">What Version of Clojure Does This Guide Cover?</h2><p>This guide covers Clojure 1.4.</p><h2 id="installing-eclipse">Installing Eclipse</h2><ol><li>Download the latest release of Eclipse from the <a href="http://www.eclipse.org/downloads/packages/eclipse-ide-java-developers/junor">official site</a>.</li><li>Install Counterclockwise plugin.
|
|
<ol><li>navigate to the "Install new Software" tab under the help menu</li><li>paste in the CCW update URL: http://ccw.cgrand.net/updatesite in the "Work with:" text field</li><li>check the "Clojure Programming" checkbox and hit the "Next" button</li></ol></li><li>Follow the instructions on the screen and restart Eclipse for changes to take effect.</li></ol><p>Counterclockwise takes care of setting up Clojure and Leiningen for you. And once the plugin is installed, you will be
|
|
able to create a new Clojure project or a new Leiningen project.</p><p>Clojure project will use Eclipse to manage dependencies, while the Leiningen project will pull dependencies from the
|
|
<code>project.clj</code> in the root folder of the project.</p><p>At this point you should have Eclipse with CCW up and running. Navigate to File->new->project in Eclipse menu.
|
|
Then select Leiningen->Leiningen project. Here you'll see the default Leiningen Template filled in.
|
|
And only thing you have to do is provide a project name. Give the project a name and hit the finish button.</p><p>You should now see a new project in your Package Explorer view on the left. If you created a project called
|
|
<code>myproject</code> then the project template will have a src folder which will contain the package folder named myproject.</p><p>Note that since Java cannot use dashes in names, all the dashes in package folders for namespaces get converted to underscores.
|
|
The package will contain a core.clj file, and its contents should look like the following:</p><pre><code class="clojure">(ns myproject.core)
|
|
|
|
(defn foo
|
|
"I don't do a whole lot."
|
|
[x]
|
|
(println x "Hello, World!"))
|
|
</code></pre><p>Let's open it and then hit the run button. You should see a REPL pop up momentarily on the bottom of the IDE.
|
|
If all went well, your project should be ready to work on (if it failed, see the <a href="index.html#troubleshooting">troubleshooting section</a>). The code that's in the file will have already been
|
|
loaded up in the REPL when we hit run, and we should now be able to call our foo function.</p><p>To do that, let's write the code which calls foo below it:</p><pre><code class="clojure">(foo "Test: ")
|
|
</code></pre><p>Then navigate the cursor inside the call body and hit CTRL+ENTER on Linux/Windows or CMD+ENTER on OS X.
|
|
You should see "Hello, World!" printed in the REPL view on the bottom. We can now change the behavior of the
|
|
<code>foo</code> function and after reloading it the new behavior will be available next time it's called.</p><p>It's also recommended to enable the "strict/paredit" mode under Preferences->Clojure->Editor section.
|
|
This will allow the editor to keep track of balancing the parens for you.</p><p>Another useful feature of the editor is the ability to select code by expression.
|
|
If you navigate inside a function and press ALT+SHIFT+UP (use CMD instead of ALT in OS X), then inner
|
|
body of the expression will be selected, pressing it again, will select the expression, and then the outer body,
|
|
and so on. Conversely pressing ALT+SHIFT+DOWN will narrow the selection. This allows you to quickly navigate nested
|
|
structures, and select code by chunks of logic as opposed to simply selecting individual lines.</p><h2 id="managing-dependencies">Managing dependencies</h2><h3 id="eclipse-dependencies">Eclipse Dependencies</h3><ol><li>Right click on the project navigate to properties.</li><li>Under properties select "Java Build Path"</li><li>Under Libraries select "Add External JARs..."</li><li>Click OK</li></ol><p>The library will show up under "Referenced Libraries" in Package Explorer.</p><h3 id="leiningen">Leiningen</h3><p>You will also see a <code>project.</code>clj` file in the root of the project. This file should look like the following:</p><pre><code class="clojure">(defproject myproject "0.1.0-SNAPSHOT"
|
|
:description "FIXME: write description"
|
|
:url "http://example.com/FIXME"
|
|
:license {:name "Eclipse Public License"
|
|
:url "http://www.eclipse.org/legal/epl-v10.html"}
|
|
:dependencies [[org.clojure/clojure "1.4.0"]])
|
|
</code></pre><p>You can add new dependencies to your project by adding them to the dependencies vector.
|
|
For example, if we wanted to add an HTTP client, head to <a href="http://clojuresphere.herokuapp.com/">ClojureSphere</a>
|
|
and navigate to the clj-http page.</p><p>From there follow the link to Clojars and copy the following:</p><pre><code class="clojure">[clj-http "0.6.4"]
|
|
</code></pre><p>now we'll simply paste it under dependencies in our <code>project.clj</code>:</p><pre><code class="clojure">:dependencies [[org.clojure/clojure "1.4.0"]
|
|
[clj-http "0.6.4"]]
|
|
</code></pre><p>In the package explorer view on the left expand "Leiningen dependencies"
|
|
and see that the clj-http jar included there. You will now have to kill our current REPL
|
|
if it is running. To do that navigate to the terminal view next to it and press the stop button.
|
|
When we start a new instance of the REPL, the library will be available for use.</p><p>In the core file we can now require the library in the namespace definition:</p><pre><code class="clojure">(ns myproject.core
|
|
(:require [clj-http.client :as client]))
|
|
</code></pre><p>and test using the client by typing</p><pre><code class="clojure">(client/get "http://google.com")
|
|
</code></pre><p>and running it as we did earlier.</p><h2 id="troubleshooting">Troubleshooting</h2><p>If when you attempt to run your code for the first time, you are asked
|
|
to select a way to run your project, rather than it just running, you
|
|
can try right clicking on the root project folder and then selecting
|
|
Leiningen->Reset Project Configuration.</p>
|
|
|
|
<div id="prev-next">
|
|
|
|
<a href="../vim_fireplace/index.html">« Clojure with Vim and fireplace.vim</a>
|
|
|
|
|
|
||
|
|
|
|
|
|
<a href="../basic_web_development/index.html">Basic Web Development »</a>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-md-3">
|
|
<div id="sidebar">
|
|
<h3>Links</h3>
|
|
<ul id="links">
|
|
|
|
<li><a href="../../about/index.html">About</a></li>
|
|
|
|
<li><a href="../../content/index.html">Table of Contents</a></li>
|
|
|
|
<li><a href="../getting_started/index.html">Getting Started with Clojure</a></li>
|
|
|
|
<li><a href="../introduction/index.html">Introduction to Clojure</a></li>
|
|
|
|
<li><a href="../emacs/index.html">Clojure with Emacs</a></li>
|
|
|
|
<li><a href="../vim_fireplace/index.html">Clojure with Vim and fireplace.vim</a></li>
|
|
|
|
<li><a href="index.html">Starting with Eclipse and Counterclockwise For Clojure Development</a></li>
|
|
|
|
<li><a href="../basic_web_development/index.html">Basic Web Development</a></li>
|
|
|
|
<li><a href="../parsing_xml_with_zippers/index.html">Parsing XML in Clojure</a></li>
|
|
|
|
<li><a href="../growing_a_dsl_with_clojure/index.html">Growing a DSL with Clojure</a></li>
|
|
|
|
<li><a href="../../language/core_overview/index.html">Overview of clojure.core, the standard Clojure library</a></li>
|
|
|
|
<li><a href="../../language/namespaces/index.html">Clojure Namespaces and Vars</a></li>
|
|
|
|
<li><a href="../../language/collections_and_sequences/index.html">Collections and Sequences in Clojure</a></li>
|
|
|
|
<li><a href="../../language/functions/index.html">Functions in Clojure</a></li>
|
|
|
|
<li><a href="../../language/laziness/index.html">Laziness in Clojure</a></li>
|
|
|
|
<li><a href="../../language/interop/index.html">Clojure interoperability with Java</a></li>
|
|
|
|
<li><a href="../../language/macros/index.html">Clojure Macros and Metaprogramming</a></li>
|
|
|
|
<li><a href="../../language/polymorphism/index.html">Polymorphism in Clojure: Protocols and Multimethods</a></li>
|
|
|
|
<li><a href="../../language/concurrency_and_parallelism/index.html">Concurrency and Parallelism in Clojure</a></li>
|
|
|
|
<li><a href="../../language/glossary/index.html">Clojure Terminology Guide</a></li>
|
|
|
|
<li><a href="../../ecosystem/libraries_directory/index.html">A Directory of Clojure Libraries</a></li>
|
|
|
|
<li><a href="../../ecosystem/libraries_authoring/index.html">Library Development and Distribution</a></li>
|
|
|
|
<li><a href="../../ecosystem/generating_documentation/index.html">Generating Documentation</a></li>
|
|
|
|
<li><a href="../../ecosystem/data_processing/index.html">Data Processing (Help Wanted)</a></li>
|
|
|
|
<li><a href="../../ecosystem/web_development/index.html">Web Development (Overview)</a></li>
|
|
|
|
<li><a href="../../ecosystem/maven/index.html">How to use Maven to build Clojure projects</a></li>
|
|
|
|
<li><a href="../../ecosystem/community/index.html">Clojure Community</a></li>
|
|
|
|
<li><a href="../../ecosystem/user_groups/index.html">Clojure User Groups</a></li>
|
|
|
|
<li><a href="../../ecosystem/running_cljug/index.html">Running a Clojure User Group</a></li>
|
|
|
|
<li><a href="../../ecosystem/books/index.html">Books about Clojure and ClojureScript</a></li>
|
|
|
|
<li><a href="../../cookbooks/data_structures/index.html">Data Structures (Help wanted)</a></li>
|
|
|
|
<li><a href="../../cookbooks/strings/index.html">Strings</a></li>
|
|
|
|
<li><a href="../../cookbooks/math/index.html">Mathematics with Clojure</a></li>
|
|
|
|
<li><a href="../../cookbooks/date_and_time/index.html">Date and Time (Help wanted)</a></li>
|
|
|
|
<li><a href="../../cookbooks/files_and_directories/index.html">Working with Files and Directories in Clojure</a></li>
|
|
|
|
<li><a href="../../cookbooks/middleware/index.html">Middleware in Clojure</a></li>
|
|
|
|
<li><a href="../../ecosystem/java_jdbc/home.html">java.jdbc - Getting Started</a></li>
|
|
|
|
<li><a href="../../ecosystem/java_jdbc/using_sql.html">java.jdbc - Manipulating data with SQL</a></li>
|
|
|
|
<li><a href="../../ecosystem/java_jdbc/using_ddl.html">java.jdbc - Using DDL and Metadata</a></li>
|
|
|
|
<li><a href="../../ecosystem/java_jdbc/reusing_connections.html">java.jdbc - How to reuse database connections</a></li>
|
|
|
|
<li><a href="../../ecosystem/core_typed/home/index.html">core.typed - User Documentation Home</a></li>
|
|
|
|
<li><a href="../../ecosystem/core_typed/user_documentation/index.html">core.typed - User Documentation</a></li>
|
|
|
|
<li><a href="../../ecosystem/core_typed/rationale/index.html">core.typed - Rationale</a></li>
|
|
|
|
<li><a href="../../ecosystem/core_typed/quick_guide.html">core.typed - Quick Guide</a></li>
|
|
|
|
<li><a href="../../ecosystem/core_typed/start/introduction_and_motivation/index.html">core.typed - Getting Started: Introduction and Motivation</a></li>
|
|
|
|
<li><a href="../../ecosystem/core_typed/types/index.html">core.typed - Types</a></li>
|
|
|
|
<li><a href="../../ecosystem/core_typed/start/annotations/index.html">core.typed - Annotations</a></li>
|
|
|
|
<li><a href="../../ecosystem/core_typed/poly_fn/index.html">core.typed - Polymorphic Functions</a></li>
|
|
|
|
<li><a href="../../ecosystem/core_typed/filters/index.html">core.typed - Filters</a></li>
|
|
|
|
<li><a href="../../ecosystem/core_typed/mm_protocol_datatypes/index.html">core.typed - Protocols</a></li>
|
|
|
|
<li><a href="../../ecosystem/core_typed/loops/index.html">core.typed - Looping constructs</a></li>
|
|
|
|
<li><a href="../../ecosystem/core_typed/function_types/index.html">core.typed - Functions</a></li>
|
|
|
|
<li><a href="../../ecosystem/core_typed/limitations/index.html">core.typed - Limitations</a></li>
|
|
|
|
</ul>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<footer>Copyright © 2021 Multiple Authors
|
|
<p style="text-align: center;">Powered by <a href="http://cryogenweb.org">Cryogen</a></p></footer>
|
|
</div>
|
|
<script src="https://code.jquery.com/jquery-1.11.0.min.js"></script>
|
|
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
|
|
<script src="../../../js/highlight.pack.js" type="application/javascript"></script>
|
|
<script>hljs.initHighlightingOnLoad();</script>
|
|
|
|
|
|
</body>
|
|
</html>
|