0
votes

I have a Clojure/Lein project, and I am successfully using a Java class I created (in ./src/com/mypackage/MyClass.java) in my Clojure code via the usual Java interop paradigm. But now I want to enhance MyClass, so in MyClass I want to import a Java package I installed via Maven via the project.clj dependencies list, but import javax.mail.Message and the like give an error: "The import javax.mail cannot be resolved". I'm admittedly very green at Java and the JVM. How can I get MyClass to know about stuff I installed via Maven via the project.clj dependencies list.

(I am already successfully using Java packages I installed via Maven via the project.clj dependencies list in my Clojure code.)

Here are my dependencies from project.clj:

  :dependencies [[org.clojure/clojure "1.10.0"]
                 [clj-http "2.0.0"]
                 [cheshire "5.9.0"]
                 [org.jsoup/jsoup "1.8.3"]
                 [javax.mail/javax.mail-api "1.6.0"]
                 [com.amazonaws/aws-java-sdk "1.11.714"]]
1
Can you update your question with your project.clj file (esp the :dependencies section)?Alan Thompson

1 Answers

1
votes

Please update your question with the contents of your project.clj file.

As a guess, you may have the wrong format for the dependencies. It should look like:

[javax.mail/javax.mail-api "1.6.0"]

You can see the details at Maven Central. How should I find the right coordinates? Just google the words

maven  central  javax.mail.Message

and it will take you to the correct Maven Central page.


Update:

Here is a java sample file that works:

package demo;
import javax.mail.Message;
public class Calc {
  public static Message msg;

  public static void show() {
    System.out.println( msg );
  }
}

and the :dependencies from project.clj (notice the suffix CLJ, not CLI):

  :dependencies [
                 [org.clojure/clojure "1.10.1"]
                 [prismatic/schema "1.1.12"]
                 [tupelo "0.9.173"]

                 [javax.mail/mail "1.4"]
                ;[javax.mail/javax.mail-api "1.6.0"]  ; also works
                ]

and results:

~/expr/demo > lein clean; lein test
Compiling 2 source files to /home/alan/expr/demo/target/default+test+test/class-files

lein test _bootstrap

-------------------------------
   Clojure 1.10.1    Java 13
-------------------------------

lein test tst.demo.core
Calling Calc/show
null

Ran 2 tests containing 0 assertions.
0 failures, 0 errors.