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.

1

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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.
If you use mvn to install the version you need to your local cache, lein will be able to find it there.
@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.
Thank you all. All of your suggestions helped and i used this link elangocheran.com/blog/2013/03/… 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.
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"]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.