dynamicly add to classpath in clojure repl to access java class files (pomegranate/add-classpath)

I have compiled class files in shortScreen/out/production/classes/com/rsw/ and want to use them in a clojure repl. I think the hangup is on add-classpath but I'm unfamiliar with what should be happening. Or how to fix it.

(use '[cemerick.pomegranate :only (add-dependencies add-classpath)])
(import 'clojure.pprint)
(def myclasses "shortScreen/out/production/classes/com/rsw/")
; do i have the correct path?
(-> ( myclasses) (file-seq) (pprint)) ; shows many class files
(.exists ( myclasses "util.class")) ; true

; add the path
(add-classpath myclasses)

; but nothing like myclasses path in list
(def thiscp (.getURLs (java.lang.ClassLoader/getSystemClassLoader)))
(pprint thiscp)
(filter (fn [s] (re-seq #"out" s)) ;myclasses path should match "out"
     (for [x thiscp]
       (.toString x)))

; fails -- but not sure if this is the correct syntax anyway
(import 'com.rsw.util)
(util/msg "test")

Edit: A reproducible example

mkdir example && cd $_
# java code
cat > << EOF
 package com.util;
 public class util {
 public static void msg(String a){

# clojure depends
cat > deps.edn << EOF
  {:deps {
    :alembic {:mvn/version "0.3.2"}
    :com.cemerick/pomegranate {:mvn/version "1.0.0"}

# compile java to class
ls # util.class

# try to load in repl

  (use '[cemerick.pomegranate :only (add-dependencies add-classpath)])
  (add-classpath (-> ( ".") .getAbsolutePath))
  (import 'com.util.util)
  ; ClassNotFoundException com.util (


  • This question is old but as there are no accepted answers I figured it might be worth a response.

    The java classloader system uses the classpath as a set of search roots and expects to find the actual classes under:

    <classpath element>/<directory hierarchy representing package name>/<class name>.class

    which in your case would look something like this:

    └── com
        └── util
            ├── Util.class

    i.e. it seems that in your example you are trying to load class com.util.util but putting the actual .class file in the root rather than under the appropriate directory hierarchy representing the com.util package name.

    I ran your reproducible example and after this change things seem to work:

    (import '[com.util Util])
    => com.util.Util

    (I upper cased the class name, otherwise I ran your example as is)