What I'm trying to do is package a large file (MIDI soundfont) in a stand-alone Maven repo / clojar, and then you can programmatically output it and use it from a separate project. This seemingly simple task turned out to be more difficult than I expected.
What would be ideal if you could directly access these resources or publish them as public vars or something like that. 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 I am facing is that it io/resourcefinds resource files only in the current class path. As soon as I try to require this namespace from another project (or from 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 access to the resource is not possible directly, I would be pleased with the solution, which involves copying the file to some path in the file system. I tried this too, but I encountered the same problem when trying to run the "copy file to file system" method from another project - the io/resourcefile still could not be found because it is not in the current class path.
I found similar questions asked earlier on SO, for example:
However, these solutions seem to apply only to copying the file, which is the resource in the current (running) project.
Can one of these two things be done?
- Access resource file from external clojar
- ,
io/resource