Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

dynapath Build Status

dynapath provides a protocol and util functions for class loaders that make their effective classpaths readable and/or modifiable.


Clojure uses a clojure.lang.DynamicClassLoader by default (an extension of, which provides .getURLs for reading the effective classpath and .addURL for modifying it. It's common for projects that need to read or modify the effective classpath to assume that a URLClassLoader is always available. But in some environments, the available class loader may not be a URLClassLoader, and may not be readable or modifiable.

Some projects (notably pomegranate) handle this by providing a protocol that can be implemented for other class loaders that may provide similar functionality.

dynapath provides a protocol that is based on an extraction of pomegranate's protocol, and is intended to be a standard way for accessing or modifying the effective classpath. Using dynapath in your library instead of assuming a class loader or implementing your own protocol provides the following benefits:

  • Your library can work with any modifiable/readable class loader without any changes
  • Any project that has already implemented DynamicClasspath for whatever esoteric class loader they are using will not need any other changes to use your library as well


Add it as a dependency:

For a Leiningen/Boot project:

[org.tcrawley/dynapath "1.1.0"]

For a maven project:


If you need to access or modify the effective classpath:

(require '[dynapath.util :as dp])

;; returns a seq of the urls for the classloader. Takes any classloader
;; (whether it implements DynamicClasspath or not) and does the right thing
(dp/classpath-urls a-classloader)
;; returns a seq of all the urls available from the classloader and its 
;; parentage chain
(dp/all-classpath-urls a-classloader)

;; adds a url to the given classloader if it is addable
(dp/add-classpath-url a-classloader a-url)

Loading the dynapath.defaults namespace will automatically implement classpath-urls and add-classpath-url for clojure.lang.DynamicClassLoader and classpath-urls for

If you need to implement DynamicClasspath:

(require '[dynapath.dynamic-classpath :as dc])

(extend-type AReadableButNotModifiableClassLoader
  (can-read? [_] true)
  (can-add? [_] false)
  (classpath-urls [cl] (seq ...)))

(extend AReadableAndModifiableClassLoader
  (assoc dc/base-readable-addable-classpath ;; implements can-read? and can-add?
         :classpath-urls (fn [cl] ...)
         :add-classpath-url (fn [cl url] ...)))

Note on URLClassLoader

Prior versions of dynapath implemented add-classpath-url for Doing so required reflective access to its protected addURL method, which would result in a warning printed to stdout under Java 9. To prevent that, that implementation has been removed, and libraries that were relying on that behavior should instead ensure they have a modifiable classloader as high in the classloader tree as they can control. For example, boot implements its own classloader to do this.

Who's using it?

Are you using it? If so, add yourself to this list and send me a PR.


Copyright © 2012-2017 Tobias Crawley

Distributed under the Eclipse Public License.


A Clojure abstraction for modifiable/readable class loaders.







No packages published