3

In Eclipse, using the CCW plug-in, I want to load a clojure file into a REPL. The problem is that I have an import statement for one of my own java classes, but apparently it is not in my classpath.

(ns my-clj-ns
  (:import [alg.gen Enumerator]))

Do I have to make jars out of every class that I want use/test in a Clojure REPL?

Currently, trying to load my clj into a REPL results in an error: "Load file in Clojure REPL" did not complete normally. Please see the log for more information. java.lang.NullPointerException

Any help would be greatly appreciated.

1

4 Answers 4

1

You can let leiningen compile these for you using,

:javac-options {:destdir "classes/"}
:java-source-path "src/main/java" ; location of Java source

options or manually compile them and move the class files to the classes/ directory. No need to create a jar.

Sign up to request clarification or add additional context in comments.

Comments

1

When you're in the ccw repl, you can hit alt-e to see the stack trace. If you're getting a NullPointerException, I don't think its a classpath issue.

Comments

0

Your code looks fine to me.

I suspect the issue is with your Eclipse Java Build Path, which determines what Eclipse includes in the classpath for your application.

In particular, if your Java class is in a separate project, you will need to either add that project to the build path (right click on project / Properties / Java Build Path / Projects) or package it as a jar.

When you start to have more sophisticated build requirements, you may also want to start looking at Maven to handle this kind of thing for you. Maven is a pain to learn / set up in the first place but it pays of in the long run.

Leiningen is also a great tool to use but I personally don't use it for the following reasons:

  1. It is great on the command line, but doesn't integrate so nicely with an Eclipse workflow
  2. Maven is more widely used and better supported in the Java world

Comments

0

There is really nice guide if you want to learn how to do this.

https://github.com/technomancy/leiningen/blob/master/doc/MIXED_PROJECTS.md

But in gist, have a project definition like the following for Java source code.

(defproject megacorp/superservice "1.0.0-SNAPSHOT"
  :description "A Clojure project with a little bit of Java sprinkled here and there"
  :source-paths      ["src/clojure"]
  :java-source-paths ["src/java"])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.