2

I have an existing Java code base. It is organized into several projects in eclipse. These projects tend to require one another. For example:

 Project A -> Common Lib 1 -> 2nd level dependency 1
           |
           -> Common Lib 2

To utilize code from other projects I can go to "Build Path" "Projects" tab and click "Add"

Is there something similar that can be done for clojure code (in eclipse), so that I can easily start using code from my existing Java projects in clojure?

Carlos Rendon
  • 6,174
  • 5
  • 34
  • 50

1 Answers1

0

Take a fresh workspace.

Create a Java project java-project with simple class.

package com.pete23;

public class Counter {
    private int i = 0;
    public int next() {
        return i++;
    }
}

Create a counterclockwise Clojure project clojure-project with simple core.clj.

(ns clojure-project.core
  (:import com.pete23.Counter))

(def counter (Counter.))

(println "java " (.next counter))
(println "java " (.next counter))

Select clojure-project. Properties -> Java Build Path -> Projects. Add java-project.

Start a fresh REPL (class path is not hot updating!). Et voila...

java 0
java 1
pete23
  • 2,204
  • 23
  • 28
  • I really appreciate these step-by-step instructions, however when I start a fresh REPL, I get `;; Clojure 1.5.1 # ClassNotFoundException com.pete23.Counter java.net.URLClassLoader$1.run (:-1)` Is there something in particular you have to do for a fresh REPL? I tried closing the process and also restarting eclipse.. – Carlos Rendon Apr 21 '14 at 18:22