반응형

개 요


Eclipse상에 Counterclockwise 플러그인을 사용하여 Clojure 개발환경 구축하는 방법을 설명합니다.



Pre-requisites


Java 6 (Eclipse 작동을 위해, Java 7, Java 5 도 사용가능)



Eclipse 설치


Eclipse Juno(4.2), Eclipse Indige(3.7) 설치 

Eclipse 사이트(http://www.eclipse.org/downloads/)에서 Eclipse IDE for Java Developers 버전을 다운로드합니다. 

Eclipse Juno(4.2) 다운로드


Eclipse Download Site Eclipse Juno 4.2




CounterClockwise Eclipse Plug-ins 설치(The Clojure plugin for Eclipse)


Counterclockwise는 Eclipse상에서 REPL 지원하고 Leiningen Project 지원 구문강조(Syntax Highlighting), 코드자동완성(Code Completion) 등의 기능을 지원합니다.


Counterclockwise 설치

- Eclipse 메뉴에서 Menu Help > Install New software...


- Work with 옆 Add... 버튼 클릭후 Name: Counterclockwise , Location: http://ccw.cgrand.net/updatesite/ 입력후 OK 버튼 

   클릭 accept licence, 마지막으로 이클립스 재시작

  (Contact all update sites during install to find required software 체크박스에 체크확인)


Counterclockwise eclipse plugin install


Counterclockwise plugin install


Counterclockwise install with Leiningen Support



- 이클립스 재시작후 메뉴 Window -> Reset Perspective 선택하여 레이아웃을 새로이 설치한 Plug-in Counterclockwise의 환경에 맞게 갱신하여 준다.


Eclipse Reset Perspective





설치테스트


여기서는 간략한 Hello World를 프린트하는 가벼운 예제를 살펴보겠습니다. 


- Clojure 프로젝트 생성

  File -> New -> Clojure Project 를 선택하여 새로운 Clojure 프로젝트 생성한다. Project name: TestClojure 으로 설정하고 Finish 하면 프로젝트 가 생성된다.

Eclipse Clojure Project Creation Wizard


Eclipse Clojure Project Creation Wizard



- TestClojure 프로젝트 서브메뉴중 src에서 Clojure Namespace를 생성한다. src 에서 마우스 오른쪽버튼 New -> Clojure Namespace, Namespace name: HelloWorld 입력후 Finish


Eclipse Clojure Project Namespace Creation Wizard



Eclipse Clojure Project Namespace Creation Wizard



(ns HelloWorld)

(def hello
    (fn [] "Hello World")
 )
REPL 입력창에 (hello) 입력후 엔터
;; Clojure 1.3.0
=> (hello)
"Hello World"



또 다른 예제


Clojure site에 있는 가장 큰값을 찾아 프린트하는 예제를 추가로 살펴보면


- Test Sample Clojure 프로젝트 생성

  File -> New -> Clojure Project 를 선택하여 새로운 Clojure 프로젝트 생성합니다. Project name: TestClojure 으로 설정하고 Finish 하면 프로젝트 가 생성됩니다.


- TestClojure 프로젝트 서브메뉴중 src에서 Clojure Namespace를 생성합니다.( src 에서 마우스 오른쪽버튼 New -> Clojure Namespace, Namespace name: GetMaxValue 입력후 Finish)



Eclipse Clojure Counterclockwise Environment



(ns HelloWorldTest)

(defn
 ^{:doc "mymax [xs+] gets the maximum value in xs using > "
   :test (fn []
             (assert (= 42  (mymax 2 42 5 4))))
   :user/comment "this is the best fn ever!"}
  mymax
  ([x] x)
  ([x y] (if (> x y) x y))
  ([x y & more]
   (reduce mymax (mymax x y) more)))

REPL 입력창에 (mymax 10 32 44 55 22 11 22 0 1) 입력후 엔터 -입력형식  (mymax X X ....)

;; Clojure 1.3.0
=> (mymax 10 32 44 55 22 11 22 0 1)
55

가장 큰값이 프린트 됩니다. 


반응형