Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 771
Daniel Wu Avatar asked Dec 12 '25 08:12

Daniel Wu


2 Answers

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.

like image 101
Chris Murphy Avatar answered Dec 15 '25 15:12

Chris Murphy


An alternative is to add to project.clj:

:repositories {"local" "file:lib"}

Create a lib directory in your project and add the jar there.

Add the lib reference in the :dependencies tag in project.clj.

This lib directory has the same structure as .m2/repository but is inside your project and local to your project

like image 41
Dan Pomohaci Avatar answered Dec 15 '25 15:12

Dan Pomohaci



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!