Search code examples
clojureleiningen

lein uberjar doesn't pack the jar file under resource into the final jar


I defined :resource-paths in profile.clj to include some special jar (vertica jdbc) file. and then I run lein uberjar: trying to pack that jar file into the standalone jar file, but after I run it, and uncompressed it, I can't find that vertica jdbc file.


Solution

  • Leiningen can create jar files, but the only place it picks them up from is your maven repository (under an .m2 directory on your machine). Once your special jar is in maven you need to refer to it as a dependency in your project.clj file.

    If your jar file was in clojars this would be quite easy - just put in a dependency - lein will fetch it into your maven repository. On the other hand if it was your own source code you would first need to lein install from the directory of that source code project.

    However I'm guessing your file is just a jar file you have, which is not an artifact in clojars. In this case you can install it into your maven repository using this maven command (here assuming my-deps.jar is your file):

    mvn install:install-file -Dfile=./my-deps.jar -DgroupId=my-deps -DartifactId=my-deps -Dversion=1.0.0 -Dpackaging=jar
    

    You can then refer to it as a dependency in the uberjar project, and then lein uberjar.

    Edit - if you don't want to use raw maven commands then consider using this leiningen library that abstracts them away for you: https://github.com/kumarshantanu/lein-localrepo.