What I'm trying to do is package a large file (a MIDI soundfont) in a standalone Maven repo/clojar, and then be able to pull it down programmatically and use it from a separate project. This seemingly simple task is proving to be more complicated than I expected.
What would be ideal is if there were a way to access these resources directly, or expose them as public vars, or something. This is the first thing I tried -- I did something like this:
(ns midi.soundfont.fluid-r3
(:require [clojure.java.io :as io]))
(def sf2
(io/file (io/resource "fluid-r3.sf2")))
However, the problem that I'm running into is that io/resource
only finds resource files on the current class path. As soon as I try to require this namespace from another project (or from the REPL), I get:
java.lang.IllegalArgumentException: Not a file: jar:file:/Users/dave/.m2/repository/midi/soundfont/fluid-r3/midi.soundfont.fluid-r3/0.1.0/midi.soundfont.fluid-r3-0.1.0.jar!/fluid-r3.sf2
If it's not possible to access the resource directly, I would be happy with a solution that involves copying the file to some path in the filesystem. I did try this as well, but I ran into the same problem when trying to run the "copy the file to the filesystem" method from a different project -- io/resource
still failed to locate the file because it's not on the current classpath.
I have found similar questions that have been asked on SO previously, such as:
- Idiomatic Clojure to copy resources from running jar to outside
- How to copy file inside jar to outside the jar?
However these solutions only seem to pertain to copying a file that is a resource in the current (running) project.
Is it possible to do one of these two things?
- Access a resource file from an external clojar
- Import the resource file into the current project, so that I can access it using
io/resource