Leiningen resource-paths

754 views
Skip to first unread message

Yura Perov

unread,
Jul 23, 2014, 6:43:38 AM7/23/14
to clo...@googlegroups.com
In my project.clj I include two jar files:

:resource-paths ["resources/exterior_jars/forssj-optimization.jar" "resources/exterior_jars/umontreal-ssj-2.5.jar"]

In my main.clj I import some objects from these dependencies:

(ns myproject.main
  (:import [umontreal.iro.lecuyer.probdist ChiSquareDist])
  ...)

So I am able to use them in main.clj:

(println "Hello")
(println (. umontreal.iro.lecuyer.probdist.ChiSquareDist cdf 5 10 3.0))
(println "Bye")

It perfectly works if I do lein run.

However, if I do lein uberjar these dependencies are not included to the standalone jar file.

I know that there exist way to use local Maven repository, but I would like to avoid this way to simplify things for anybody who wants to download the source code and compile it quickly.

Could you advise, please, is it possible to somehow force Leiningen to include these two resources in the final standalone jar?

Thank you.

Thomas Heller

unread,
Jul 24, 2014, 4:18:51 AM7/24/14
to clo...@googlegroups.com
Hey,

I had this problem with a jar from Bing which is not available on maven.

You can use a local repo without any plugins or extra work for "others".

Try this:

Pick a directory for your local maven repo, should be inside your git repo. I'm using "maven".

Take your jar and run

mvn deploy:deploy-file -Dfile=lib/bing-reporting.jar -DartifactId=bing-reporting -Dversion=1.0.0 -DgroupId=smartchecker -Dpackaging=jar -Durl=file:maven

Obviously change your arguments, the important part is: -Durl=file:maven where "maven" is the directory.

Then in your project.xml

add

:repositories {"local" "file:maven"}

and depend on the jar as usual

[smartchecker/bing-reporting "1.0.0"]

uberjar works as well as the rest.

Hope that helps,
/thomas

Yura Perov

unread,
Jul 24, 2014, 9:22:37 AM7/24/14
to clo...@googlegroups.com
Dear Thomas Heller,

Thank you very much for your reply.

As I mentioned in my initial post (sorry, it was a bit long), I successfully managed local Maven repository to work with Leiningen:
I know that there exist way to use local Maven repository, but I would like to avoid this way to simplify things for anybody who wants to download the source code and compile it quickly.

However, local Maven is an additional issue developers should care about, and I am trying to find a way to avoid using it at least for exterior jars I am sure we do not need to update or care about their versions.

I am trying to understand how does Leiningen process :resource-paths directive and if there is a way to force classes from exterior jars be included in the producing standalone jar.

Yours faithfully,
Yura

Thomas Heller

unread,
Jul 24, 2014, 9:43:29 AM7/24/14
to clo...@googlegroups.com
I don't quite understand the issue against using the way I described.

Assuming you keep everything in a git repo (inclucing that maven directory), only you have to execute the mvn command ONCE, all it does it put the file into the "correct" directory and generate the needed metadata files. After that users of your code just check out everything and run lein like normal. No extra maven commands to run or setup. IMHO its just the same as depending on the jar via :resource-paths. As I understand it there are other ways to setup local Maven depositories, maybe you tried it a different way which may require more steps. IIRC its mvn deploy:deploy-file vs install-file or something, can't remember exactly.

As for :resource-paths and how leiningen handles them: they are just appended to the classpath, thats about it. uberjar doesn't identify jars in there so just copies them INSIDE the uberjar so you'll have jar in a jar which java doesnt understand.

/thomas

Laurent PETIT

unread,
Jul 24, 2014, 12:43:57 PM7/24/14
to clo...@googlegroups.com
My suggestion then: instead of storing the jar files, unzip them in their respective resource directories? Should solve the über jar problem if Leiningen isn't too strict in filtering what's copied from resources folders to final build dir. 
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Yura Perov

unread,
Jul 25, 2014, 10:47:52 AM7/25/14
to clo...@googlegroups.com
Dear Thomas Heller, Dear Laurent Petit,
 
I don't quite understand the issue against using the way I described.
 
We just did not want to have an additional dependency of Maven. For example, Maven should be independentally installed on Windows.

My suggestion then: instead of storing the jar files, unzip them in their respective resource directories? Should solve the über jar problem if Leiningen isn't too strict in filtering what's copied from resources folders to final build dir. 

Yes, this is what we wanted, but on the other hand it creates too many files in the repository.

***

For our project we have decided to depend on Maven and require user to install Maven and execute these several commands to add jars to the local repository.

Thank you very much!

Yours faithfully,
Yura

Shantanu Kumar

unread,
Jul 25, 2014, 12:02:54 PM7/25/14
to clo...@googlegroups.com

For our project we have decided to depend on Maven and require user to install Maven and execute these several commands to add jars to the local repository.

You could probably have a script that uses lein-localrepo (to install all dependencies in one go) if you don't want to install Maven. (Sorry about the plug.)


Shantanu
Reply all
Reply to author
Forward
0 new messages