1

So.. I have this problem (the one in the title). Just to give a background about what I did: Create a Java class called Carro:

public class Carro{
  public Carro(){}
  public void turnon(String sound){
     System.out.println(sound);
  }
}

I've compile it:

javac Carro.java

And created a .jar:

jar -cf Carro.jar Carro.class

So, I created a new lein project: lein new test

Created a /lib directory and pasted the Carro.jar in it.

Create a folder called carro in test/src/ directory and create a .clj file, called car.clj:

(ns carro.car
  (:import [Carro] )
)

(defn callCarro [] 
  (let [car (new Carro)]
     (.turnon "vruuum!" car)
  )
)

After all of that, I edited the project.clj file and add a :import [Carro] after the last parenthesis.

So, when I run the project using lein repl, I get this error:

    $ lein repl
    user=> (require 'carr.car :reload)
    CompilerException java.lang.IllegalArgumentException: 
Unable to resolve classname: Carro, compiling:(carro/car.clj:6) 

Any ideas to solve this... Problem?

1
  • this or this might be helpful. Commented Mar 4, 2013 at 22:20

2 Answers 2

2

Leiningen 2 relies on maven to manage dependencies. Version 1 used to copy jars to the lib directory but this behavior was removed (see https://github.com/technomancy/leiningen/blob/stable/doc/FAQ.md). If you need a certain jar for your project, the easiest way is to install that jar on your local maven repo and let leiningen do the rest.

Maven (and so leiningen) needs a version, a group and an artifact for the jar you are working with (see https://github.com/technomancy/leiningen/blob/master/doc/TUTORIAL.md#artifact-ids-groups-and-versions). So our first step will be to rename Carro.jar to Carro-0.1.0.jar. To make things a little easier, lets use a leiningen plugin to do the rest. Add the lein-localrepo plugin to your project.clj, something like:

(defproject foo "0.1.0-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.4.0"]]
  :plugins [[lein-localrepo "0.4.1"]])

Then you can ask leiningen for the coordinates of the Carro dependency:

$ lein localrepo coords Carro-0.1.0.jar
Carro-0.1.0.jar Carro/Carro 0.1.0

That last part is the info needed to install to the mvn repo:

$ lein localrepo install Carro-0.1.0.jar Carro/Carro 0.1.0

After that,the jar is installed in your mvn repository: ~/.m2/repository/Carro/Carro/0.1.0/Carro-0.1.0.jar. So finally, add the newly installed dependency to project.clj:

(defproject foo "0.1.0-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.4.0"]
                 [Carro/Carro "0.1.0"]]
  :plugins [[lein-localrepo "0.4.1"]])

And then from the repl:

$ lein repl
user=> (new Carro)
#<Carro Carro@7c04703c>
Sign up to request clarification or add additional context in comments.

Comments

0

I suspect there may be multiple causes:

  • Clojure has trouble loading classes without a package which causes this.
  • that is not the typical location for test classes if you are using Leiningen
  • If you didn't run (import 'Classname) from the repl you will need to do that as well.

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.