classpath "empty" when classpath 0.2.2 used with clojure maven plugin 1.3.20+


I have a project that is storing data in resources that it expects to find on the classpath. When the project uses java.classpath 0.2.2 and clojure-maven-plugin 1.3.20+ calling (java.classpath/classpath) produces unexpected results - it shows some sun stuff, but no dependencies, no clojure, none of my code or resources. Clojure seems to be functioning though, it's just calls in to the classpath api that pose issues.

For comparison:

java.classpath 0.1.0 and c-m-plugin 1.3.9 behaves as expected.

java.classpath 0.1.0 and c-m-plugin 1.3.20 can create problems and sometimes only shows one item on the classpath that appears to be an empty manifest.

crosspost to clojure-maven-plugin here:


Apache Maven 3.2.2 (45f7c06d68e745d05611f7fd14efb6594181933e; 2014-06-17T07:51:42-06:00)
Maven home: /data/hudson/apache-maven-3.2.2
Java version: 1.7.0_05-icedtea, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-1.7.0-openjdk-
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.9.10-100.fc17.x86_64", arch: "amd64", family: "unix"


Stuart Sierra
July 18, 2014, 10:10 PM

On further digging in the OpenJDK source code, URLClassLoader reads JAR manifest files lazily, as needed, to load classes or resources. To find the list of all URLs that a URLClassLoader might open, you would have to reimplement this logic to read all the manifest files. It also has to be recursive (JAR manifest references another JAR with a manifest) and detect cycles.

July 19, 2014, 9:52 PM

Comment made by: drlivingston

Thank you for looking into this.
Am I understanding that this is the correct / desired behavior for what clojure-maven-plungin and should be doing together?

So I was going into jar files, (although I've realized I don't think I'm looking into nested jar files - does the classloader look into nested files?) and now you are saying there's a third case I will have to cover too, right?: manifest files? Is there a utility method in for reading them?

I was using code like this to identify everything accessible on the classpath:


Stuart Sierra
July 22, 2014, 12:58 PM

Currently, handles neither JAR Manifest files nor nested JAR files. As I described in my previous comment, implementing support for this would be difficult and is not likely to be a priority for me any time soon. I would be willing to review a patch to add this capability, but it would have to prove that it protects against recursive cycles.

By my reading of the JAR File Specification, the behavior of clojure-maven-plugin could be considered against the spirit of the JAR spec, which decribes the "Class-Path" manifest attribute this way:

"Class-Path: The value of this attribute specifies the relative URLs of the extensions or libraries that this application or extension needs." (emphasis added)

The clojure-maven-plugin is creating a JAR manifest with a "Class-Path" attribute containing absolute URLs to other JAR files which are not embedded in the JAR containing the manifest.

I have always assumed that JAR manifest files with Class-Path attributes are used only when packaging complete applications or JDK extensions, not as a mechanism for specifying the class-path during development. Clearly it is possible, as the current clojure-maven-plugin demonstrates, but it is not a feature I would want to rely on.

In general, the JDK does not support enumerating all files on the classpath, since the classpath can include URLs to remote resources which are downloaded as needed.

July 22, 2014, 6:20 PM

Comment made by: drlivingston

Interesting. I didn't realize some of this was so flexible.
Thanks for your comments.

So iterating recursively over the CP seem like it might be a bad thing to do?, although I guess it's no worse than if you happened to ask for something to be loaded that's found in the very last, deepest corner of the CP, right?

I have been putting resource files on the CP and then having the application find them with a prefix of their names. e.g., find all "" and I get "" and "" etc. without the application needing to be aware of what's there or the need for manifests to be generated or maintained. Is this an known anti-pattern for working with resources on the classpath?

Stuart Sierra
July 23, 2014, 1:13 PM

Is this an known anti-pattern for working with resources on the classpath?



Stuart Sierra