Как правильно импортировать библиотеку Twilio Java в Clojure? - PullRequest
1 голос
/ 03 марта 2020

Документы Twilio для Java Lib

MVN для этой библиотеки

Я пытаюсь использовать Twilio из Clojure. Довольно плохо знаком с разработчиком Clojure, поэтому я пытаюсь в общем разобраться с импортом библиотек.

Мой project.clj:

(defproject magical-new-project "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
            :url "https://www.eclipse.org/legal/epl-2.0/"}
  :dependencies [[org.clojure/clojure "1.10.0"]
                 ;[com.twilio.sdk/twilio "7.47.5"]
                 [clj-twilio "0.2.0"]]
  :repl-options {:init-ns magical-new-project.core})

Мой core.clj:

(ns magical-new-project.core
  (:import [com.twilio.sdk]))

(defn foo
  "I don't do a whole lot."
  [x]
  (println x "Fuck off, World!"))

Мой след стека:

  Show: Project-Only All 
  Hide: Clojure Java REPL Tooling Duplicates  (11 frames hidden)

2. Unhandled clojure.lang.Compiler$CompilerException
   Error compiling *cider-repl tutorials/magical-new-project:localhost:63188(clj)* at (1:1)
   #:clojure.error{:phase :compile-syntax-check,
                   :line 1,
                   :column 1,
                   :source
                   "*cider-repl tutorials/magical-new-project:localhost:63188(clj)*"}
                  core.clj: 5867  clojure.core/throw-if
                  core.clj: 5854  clojure.core/throw-if
               RestFn.java:  425  clojure.lang.RestFn/invoke
                  core.clj: 5988  clojure.core/load-libs
                  core.clj: 5969  clojure.core/load-libs
               RestFn.java:  137  clojure.lang.RestFn/applyTo
                  core.clj:  667  clojure.core/apply
                  core.clj: 6007  clojure.core/require
                  core.clj: 6007  clojure.core/require
               RestFn.java:  421  clojure.lang.RestFn/invoke
                      REPL:    1  magical-new-project.core/eval6614
                      REPL:    1  magical-new-project.core/eval6614
             Compiler.java: 7176  clojure.lang.Compiler/eval
             Compiler.java: 7131  clojure.lang.Compiler/eval
                  core.clj: 3214  clojure.core/eval
                  core.clj: 3210  clojure.core/eval
                  main.clj:  414  clojure.main/repl/read-eval-print/fn
                  main.clj:  414  clojure.main/repl/read-eval-print
                  main.clj:  435  clojure.main/repl/fn
                  main.clj:  435  clojure.main/repl
                  main.clj:  345  clojure.main/repl
               RestFn.java: 1523  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   79  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:   55  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:  142  nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
                  AFn.java:   22  clojure.lang.AFn/run
               session.clj:  171  nrepl.middleware.session/session-exec/main-loop/fn
               session.clj:  170  nrepl.middleware.session/session-exec/main-loop
                  AFn.java:   22  clojure.lang.AFn/run
               Thread.java:  835  java.lang.Thread/run

1. Caused by java.lang.Exception
   prefix cannot be nil

                  core.clj: 5988  clojure.core/load-libs
                  core.clj: 5969  clojure.core/load-libs
               RestFn.java:  137  clojure.lang.RestFn/applyTo
                  core.clj:  667  clojure.core/apply
                  core.clj: 6007  clojure.core/require
                  core.clj: 6007  clojure.core/require
               RestFn.java:  421  clojure.lang.RestFn/invoke
                      REPL:    1  magical-new-project.core/eval6614
                      REPL:    1  magical-new-project.core/eval6614
             Compiler.java: 7176  clojure.lang.Compiler/eval
             Compiler.java: 7131  clojure.lang.Compiler/eval
                  core.clj: 3214  clojure.core/eval
                  core.clj: 3210  clojure.core/eval
                  main.clj:  414  clojure.main/repl/read-eval-print/fn
                  main.clj:  414  clojure.main/repl/read-eval-print
                  main.clj:  435  clojure.main/repl/fn
                  main.clj:  435  clojure.main/repl
                  main.clj:  345  clojure.main/repl
               RestFn.java: 1523  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   79  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:   55  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:  142  nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
                  AFn.java:   22  clojure.lang.AFn/run
               session.clj:  171  nrepl.middleware.session/session-exec/main-loop/fn
               session.clj:  170  nrepl.middleware.session/session-exec/main-loop
                  AFn.java:   22  clojure.lang.AFn/run
               Thread.java:  835  java.lang.Thread/run

Может кто-нибудь предложить мне, какие ошибки я совершаю с этим, и какова должна быть правильная структура импорта?

Отредактировано:

Я изменил свой импорт в core.clj:

(ns magical-new-project.core
  (:import [com.twilio.http Request Response]))

и теперь я получаю:

2. Unhandled clojure.lang.Compiler$CompilerException
   Error compiling magical_new_project/core.clj at (1:1)
   #:clojure.error{:phase :compile-syntax-check,
                   :line 1,
                   :column 1,
                   :source "magical_new_project/core.clj"}
             Compiler.java: 7647  clojure.lang.Compiler/load
                   RT.java:  381  clojure.lang.RT/loadResourceScript
                   RT.java:  372  clojure.lang.RT/loadResourceScript
                   RT.java:  463  clojure.lang.RT/load
                   RT.java:  428  clojure.lang.RT/load
                  core.clj: 6126  clojure.core/load/fn
                  core.clj: 6125  clojure.core/load
                  core.clj: 6109  clojure.core/load
               RestFn.java:  408  clojure.lang.RestFn/invoke
                  core.clj: 5908  clojure.core/load-one
                  core.clj: 5924  clojure.core/load-all/fn/fn
                  core.clj: 5924  clojure.core/load-all/fn
                  AFn.java:   18  clojure.lang.AFn/call
   LockingTransaction.java:  273  clojure.lang.LockingTransaction/run
   LockingTransaction.java:  229  clojure.lang.LockingTransaction/runInTransaction
                  core.clj: 5922  clojure.core/load-all
                  core.clj: 5916  clojure.core/load-all
                  core.clj: 5948  clojure.core/load-lib/fn
                  core.clj: 5947  clojure.core/load-lib
                  core.clj: 5928  clojure.core/load-lib
               RestFn.java:  142  clojure.lang.RestFn/applyTo
                  core.clj:  667  clojure.core/apply
                  core.clj: 5985  clojure.core/load-libs
                  core.clj: 5969  clojure.core/load-libs
               RestFn.java:  137  clojure.lang.RestFn/applyTo
                  core.clj:  667  clojure.core/apply
                  core.clj: 6007  clojure.core/require
                  core.clj: 6007  clojure.core/require
               RestFn.java:  421  clojure.lang.RestFn/invoke
                      REPL:    1  magical-new-project.core/eval6622
                      REPL:    1  magical-new-project.core/eval6622
             Compiler.java: 7176  clojure.lang.Compiler/eval
             Compiler.java: 7131  clojure.lang.Compiler/eval
                  core.clj: 3214  clojure.core/eval
                  core.clj: 3210  clojure.core/eval
                  main.clj:  414  clojure.main/repl/read-eval-print/fn
                  main.clj:  414  clojure.main/repl/read-eval-print
                  main.clj:  435  clojure.main/repl/fn
                  main.clj:  435  clojure.main/repl
                  main.clj:  345  clojure.main/repl
               RestFn.java: 1523  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   79  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:   55  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:  142  nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
                  AFn.java:   22  clojure.lang.AFn/run
               session.clj:  171  nrepl.middleware.session/session-exec/main-loop/fn
               session.clj:  170  nrepl.middleware.session/session-exec/main-loop
                  AFn.java:   22  clojure.lang.AFn/run
               Thread.java:  835  java.lang.Thread/run

1. Caused by java.lang.ClassNotFoundException
   com.twilio.http.Request

       URLClassLoader.java:  436  java.net.URLClassLoader/findClass
   DynamicClassLoader.java:   69  clojure.lang.DynamicClassLoader/findClass
          ClassLoader.java:  588  java.lang.ClassLoader/loadClass
   DynamicClassLoader.java:   77  clojure.lang.DynamicClassLoader/loadClass
          ClassLoader.java:  521  java.lang.ClassLoader/loadClass
                Class.java:   -2  java.lang.Class/forName0
                Class.java:  415  java.lang.Class/forName
                   RT.java: 2207  clojure.lang.RT/classForName
                   RT.java: 2220  clojure.lang.RT/classForNameNonLoading
                  core.clj:    1  magical-new-project.core/eval6626/loading--auto--
                  core.clj:    1  magical-new-project.core/eval6626
                  core.clj:    1  magical-new-project.core/eval6626
             Compiler.java: 7176  clojure.lang.Compiler/eval
             Compiler.java: 7165  clojure.lang.Compiler/eval
             Compiler.java: 7635  clojure.lang.Compiler/load
                   RT.java:  381  clojure.lang.RT/loadResourceScript
                   RT.java:  372  clojure.lang.RT/loadResourceScript
                   RT.java:  463  clojure.lang.RT/load
                   RT.java:  428  clojure.lang.RT/load
                  core.clj: 6126  clojure.core/load/fn
                  core.clj: 6125  clojure.core/load
                  core.clj: 6109  clojure.core/load
               RestFn.java:  408  clojure.lang.RestFn/invoke
                  core.clj: 5908  clojure.core/load-one
                  core.clj: 5924  clojure.core/load-all/fn/fn
                  core.clj: 5924  clojure.core/load-all/fn
                  AFn.java:   18  clojure.lang.AFn/call
   LockingTransaction.java:  273  clojure.lang.LockingTransaction/run
   LockingTransaction.java:  229  clojure.lang.LockingTransaction/runInTransaction
                  core.clj: 5922  clojure.core/load-all
                  core.clj: 5916  clojure.core/load-all
                  core.clj: 5948  clojure.core/load-lib/fn
                  core.clj: 5947  clojure.core/load-lib
                  core.clj: 5928  clojure.core/load-lib
               RestFn.java:  142  clojure.lang.RestFn/applyTo
                  core.clj:  667  clojure.core/apply
                  core.clj: 5985  clojure.core/load-libs
                  core.clj: 5969  clojure.core/load-libs
               RestFn.java:  137  clojure.lang.RestFn/applyTo
                  core.clj:  667  clojure.core/apply
                  core.clj: 6007  clojure.core/require
                  core.clj: 6007  clojure.core/require
               RestFn.java:  421  clojure.lang.RestFn/invoke
                      REPL:    1  magical-new-project.core/eval6622
                      REPL:    1  magical-new-project.core/eval6622
             Compiler.java: 7176  clojure.lang.Compiler/eval
             Compiler.java: 7131  clojure.lang.Compiler/eval
                  core.clj: 3214  clojure.core/eval
                  core.clj: 3210  clojure.core/eval
                  main.clj:  414  clojure.main/repl/read-eval-print/fn
                  main.clj:  414  clojure.main/repl/read-eval-print
                  main.clj:  435  clojure.main/repl/fn
                  main.clj:  435  clojure.main/repl
                  main.clj:  345  clojure.main/repl
               RestFn.java: 1523  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   79  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:   55  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:  142  nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
                  AFn.java:   22  clojure.lang.AFn/run
               session.clj:  171  nrepl.middleware.session/session-exec/main-loop/fn
               session.clj:  170  nrepl.middleware.session/session-exec/main-loop
                  AFn.java:   22  clojure.lang.AFn/run
               Thread.java:  835  java.lang.Thread/run
    ```

Now I'm wondering if my project.clj is looking okay?

EDIT 2:

$ lein deps: дерево

Retrieving clj-twilio/clj-twilio/0.2.0/clj-twilio-0.2.0.pom from clojars
Retrieving org/clojure/clojure-contrib/1.2.0/clojure-contrib-1.2.0.pom from central
Retrieving org/clojure/clojure-contrib/1.2.0/clojure-contrib-1.2.0.jar from central
Retrieving clj-twilio/clj-twilio/0.2.0/clj-twilio-0.2.0.jar from clojars
 [clj-twilio "0.2.0"]
   [org.clojure/clojure-contrib "1.2.0"]
 [clojure-complete "0.2.5" :exclusions [[org.clojure/clojure]]]
 [nrepl "0.6.0" :exclusions [[org.clojure/clojure]]]
 [org.clojure/clojure "1.10.0"]
   [org.clojure/core.specs.alpha "0.2.44"]
   [org.clojure/spec.alpha "0.2.176"]
 [proto-repl "0.3.1"]
   [compliment "0.2.7"]
     [defprecated "0.1.3"]
   [org.clojure/core.async "0.2.374"]
     [org.clojure/tools.analyzer.jvm "0.6.9"]
       [org.clojure/core.memoize "0.5.8"]
         [org.clojure/core.cache "0.6.4"]
           [org.clojure/data.priority-map "0.0.4"]
       [org.clojure/tools.analyzer "0.6.7"]
       [org.clojure/tools.reader "1.0.0-alpha1"]
       [org.ow2.asm/asm-all "4.2"]
   [org.clojure/tools.namespace "0.2.11"]


EDIT 

`project.clj`

(defproject magical-new-project "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
            :url "https://www.eclipse.org/legal/epl-2.0/"}
  :dependencies [[org.clojure/clojure "1.10.0"]
                 [com.twilio.sdk/twilio "7.47.5"]]
  :repl-options {:init-ns magical-new-project.core})
Stack trace:

    2. Unhandled clojure.lang.Compiler$CompilerException
       Error compiling *cider-repl tutorials/magical-new-project:localhost:63188(clj)* at (1:1)
       #:clojure.error{:phase :compile-syntax-check,
                       :line 1,
                       :column 1,
                       :source
                       "*cider-repl tutorials/magical-new-project:localhost:63188(clj)*"}
                      core.clj: 5867  clojure.core/throw-if
                      core.clj: 5854  clojure.core/throw-if
                   RestFn.java:  425  clojure.lang.RestFn/invoke
                      core.clj: 5988  clojure.core/load-libs
                      core.clj: 5969  clojure.core/load-libs
                   RestFn.java:  137  clojure.lang.RestFn/applyTo
                      core.clj:  667  clojure.core/apply
                      core.clj: 6007  clojure.core/require
                      core.clj: 6007  clojure.core/require
                   RestFn.java:  421  clojure.lang.RestFn/invoke
                          REPL:    1  magical-new-project.core/eval6648
                          REPL:    1  magical-new-project.core/eval6648
                 Compiler.java: 7176  clojure.lang.Compiler/eval
                 Compiler.java: 7131  clojure.lang.Compiler/eval
                      core.clj: 3214  clojure.core/eval
                      core.clj: 3210  clojure.core/eval
                      main.clj:  414  clojure.main/repl/read-eval-print/fn
                      main.clj:  414  clojure.main/repl/read-eval-print
                      main.clj:  435  clojure.main/repl/fn
                      main.clj:  435  clojure.main/repl
                      main.clj:  345  clojure.main/repl
                   RestFn.java: 1523  clojure.lang.RestFn/invoke
        interruptible_eval.clj:   79  nrepl.middleware.interruptible-eval/evaluate
        interruptible_eval.clj:   55  nrepl.middleware.interruptible-eval/evaluate
        interruptible_eval.clj:  142  nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
                      AFn.java:   22  clojure.lang.AFn/run
                   session.clj:  171  nrepl.middleware.session/session-exec/main-loop/fn
                   session.clj:  170  nrepl.middleware.session/session-exec/main-loop
                      AFn.java:   22  clojure.lang.AFn/run
                   Thread.java:  835  java.lang.Thread/run

    1. Caused by java.lang.Exception
       prefix cannot be nil

                      core.clj: 5988  clojure.core/load-libs
                      core.clj: 5969  clojure.core/load-libs
                   RestFn.java:  137  clojure.lang.RestFn/applyTo
                      core.clj:  667  clojure.core/apply
                      core.clj: 6007  clojure.core/require
                      core.clj: 6007  clojure.core/require
                   RestFn.java:  421  clojure.lang.RestFn/invoke
                          REPL:    1  magical-new-project.core/eval6648
                          REPL:    1  magical-new-project.core/eval6648
                 Compiler.java: 7176  clojure.lang.Compiler/eval
                 Compiler.java: 7131  clojure.lang.Compiler/eval
                      core.clj: 3214  clojure.core/eval
                      core.clj: 3210  clojure.core/eval
                      main.clj:  414  clojure.main/repl/read-eval-print/fn
                      main.clj:  414  clojure.main/repl/read-eval-print
                      main.clj:  435  clojure.main/repl/fn
                      main.clj:  435  clojure.main/repl
                      main.clj:  345  clojure.main/repl
                   RestFn.java: 1523  clojure.lang.RestFn/invoke
        interruptible_eval.clj:   79  nrepl.middleware.interruptible-eval/evaluate
        interruptible_eval.clj:   55  nrepl.middleware.interruptible-eval/evaluate
        interruptible_eval.clj:  142  nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
                      AFn.java:   22  clojure.lang.AFn/run
                   session.clj:  171  nrepl.middleware.session/session-exec/main-loop/fn
                   session.clj:  170  nrepl.middleware.session/session-exec/main-loop
                      AFn.java:   22  clojure.lang.AFn/run
                   Thread.java:  835  java.lang.Thread/run
```
...