简体   繁体   中英

How to use java project in eclipse from clojure project

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM