0

I am getting ClassNotFoundException when I import my custom java class in my clojure project.

;project.clj
(defproject subclass "0.1.0-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.8.0"]]
  :java-source-paths ["src/java"]
  :main subclass.core
  :aot [subclass.core]
  :target-path "target/%s"
  :profiles {:uberjar {:aot :all}})

;src/subclass/core.clj
(ns subclass.core
    (:gen-class
     :extends BaseClass
     :exposes-methods {greet pgreet})
    (:import BaseClass))  ;This is being qualified as java.lang.BaseClass

(defn -main [& args])

//src/java/BaseClass.java
public class BaseClass {
    public String greet() {
        return "Hello from BaseClass";
    }
}

When I run lein repl I am getting the following error:

Compiling subclass.core
java.lang.ClassNotFoundException: java.lang.BaseClass, compiling:(subclass/core.clj:1:1)
Exception in thread "main" java.lang.ClassNotFoundException: java.lang.BaseClass, compiling:(subclas
s/core.clj:1:1)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:6875)
        at clojure.lang.Compiler.analyze(Compiler.java:6669)
        at clojure.lang.Compiler.analyze(Compiler.java:6625)
        ... snip ...
        at clojure.lang.AFn.applyToHelper(AFn.java:156)
        at clojure.lang.Var.applyTo(Var.java:700)
        at clojure.main.main(main.java:37)
Caused by: java.lang.ClassNotFoundException: java.lang.Baseclass
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at clojure.lang.DynamicClassLoader.findClass(DynamicClassLoader.java:69)
        ... snip ...
        ... 54 more
Compilation failed: Subprocess failed

The BaseClasss is getting qualified as java.lang.BaseClass which fails. How will refer BaseClass from src/java? Thanks.

4
  • Baseclass is not the same thing as BaseClass. Commented Dec 15, 2016 at 6:38
  • Sorry, updated the post. Commented Dec 15, 2016 at 6:43
  • Alan Thompson: Thanks, that works. Commented Dec 15, 2016 at 8:10
  • @AlanThompson Please write this in an answer so we can close that question. Commented Jul 11, 2017 at 8:20

1 Answer 1

1

Try putting BaseClass in a package. Java & Clojure don't like "naked" classes.

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

Comments

Your Answer

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