1

I am new to clojure. I am trying to use java jar in clojure, but it doesn't seem to work. I have built the path, put the jar physically in the lib folder of the project and tried :

(import 'jml.clustering.NMF)

But i get this exception :

ClassNotFoundException jml.clustering.NMF java.net.URLClassLoader.findClass (:-1)

How do i fix this? Thank you in advance.

Savas
  • 47
  • 5
  • Related: [leiningen - how to add dependencies for local jars](http://stackoverflow.com/questions/2404426/) – DaoWen Apr 12 '15 at 03:44

2 Answers2

1

Just sticking the jar in the lib directory won't force leiningen to include the jar in the classpath. Instead, try adding the library to your project's dependencies list:

:dependencies [[org.clojure/clojure "1.6.0"]
               [org.realityforge.jml/jml "0.9.3"]]

You can find the group/id and version of available libraries by searching one of the supported public repositories. I searched maven.org for jml to find the info I used above.

Note that this doesn't use your local copy of the jar, but rather downloads a new one from the repository and caches it somewhere. This might not be ideal, but for my own projects I've found that getting lein to use a local jar is just way too big of a headache. Using one from clojars or maven.org is so much simpler that I can overlook having to download a new copy.

DaoWen
  • 32,589
  • 6
  • 74
  • 101
  • Thank you for clarification :) , this would probably work, but this isn't the jml I'm trying to use, and as I see the one i require is not registered at maven.org :( My headache continues... Thanks anyway. – Savas Apr 11 '15 at 19:23
  • If you use `mvn` to install the version you need to your local cache, `lein` will be able to find it there. – noisesmith Apr 11 '15 at 21:42
  • @Savas - lein makes it really hard to use anything that's not in a public repository. I think they actually do this purposely, because they want to encourage developers to make it easy for other people to copy a project and get it working on a different system. I posted a link to another related question in a comment above. I hope that helps. – DaoWen Apr 12 '15 at 03:50
  • Thank you all. All of your suggestions helped and i used this link http://www.elangocheran.com/blog/2013/03/installing-jar-files-locally-for-leiningen-2/ also to resolve my problem. I created an additional one for myself before when i named my user using, among other characters, this one "&", so it was very "fun" playing with cmd. – Savas Apr 13 '15 at 20:40
0

If the JAR is your own, you can follow these steps to use a local JAR not available in any maven repository.

Given a Jar: foo.jar

Into your Clojure project dir:

mvn deploy:deploy-file -DgroupId=local -DartifactId=foo \
 -Dversion=1.0.0 -Dpackaging=jar -Dfile=foo.jar \
 -Durl=file:repo

Edit your project.clj to include the new dependency:

 [local/foo "1.0.0"]
Édipo Féderle
  • 4,169
  • 5
  • 31
  • 35