简体   繁体   English

我的 clojure 从本地 jar 文件导入 class 如何不起作用?

[英]How is my clojure import of a class from a local jar file not working?

I've been trying to import a class from a local jar file into a Clojure program (this is a cli project and my dev environment is Calva in VSCode in Windows 10).我一直在尝试将本地 jar 文件中的 class 导入到 Clojure 程序中(这是一个 cli 项目,我的开发环境是 Windows 10 中 VSCode 中的 Calva)。 My project file is at C:\Users\fadrian\Projects\motive-cql-builder\mercator-server.我的项目文件位于 C:\Users\fadrian\Projects\motive-cql-builder\mercator-server。 My deps.edn file is in this folder and looks like this:我的 deps.edn 文件位于此文件夹中,如下所示:

{:paths
 ["src"
  "C:\\Users\\fadrian\\Projects\\motive-cql-builder\\mercator-server\\resources\\jars\\apelon\\dtscore-4.6.1-838.jar"
  ]

 :deps
 {org.clojure/clojure {:mvn/version "1.10.3"}
  compojure/compojure {:mvn/version "1.6.2"}
  http-kit/http-kit {:mvn/version "2.5.3"}
  ring/ring-json {:mvn/version "0.5.1"}
  ring-cors/ring-cors {:mvn/version "0.1.13"}
  org.clojure/data.json {:mvn/version "2.4.0"}
  mercator/mapper {:local/root "../mercator"}
  mercator/expander {:local/root "../mercator"}
  mercator/primitives {:local/root "../mercator"}
  mercator/templates {:local/root "../mercator"}
  cheshire/cheshire {:mvn/version "5.0.2"}
   }

 :jvm-opts ["-XX:-OmitStackTraceInFastThrow"]
 
  :aliases {;; build an uberjar (application) with AOT compilation by default:
            :dev {}
            
            :uberjar {:replace-deps {com.github.seancorfield/depstar {:mvn/version "2.1.303"}}
                      :exec-fn hf.depstar/uberjar
                      :exec-args {:aot true}}
  ;; build a jar (library):
            :jar {:replace-deps {com.github.seancorfield/depstar {:mvn/version "2.1.303"}}
                  :exec-fn hf.depstar/jar
                  :exec-args {}}}}

The class I'm trying to include is in the file resources\jars\apelon\dtscore-4.6.1-838.jar in the jarfile folder \com\apelon\dts\client.我要包含的 class 位于 jarfile 文件夹 \com\apelon\dts\client 的文件 resources\jars\apelon\dtscore-4.6.1-838.jar 中。 It is called ServerConnectionEJB.class.它称为 ServerConnectionEJB.class。 I have verified that the file is in this location in the jarfile.我已经验证该文件位于 jarfile 中的这个位置。

The ns statement in my code file is this:我的代码文件中的ns语句是这样的:

(ns mercator-server.core
  (:gen-class)
  (:require [compojure.core :refer [defroutes GET POST]]
            [mercator.expander :refer [ednize-json-keywords]]
            [mercator.mapper :refer [translate json-template-sets]]
            [org.httpkit.server :refer [run-server]]
            [ring.middleware.cors :refer [wrap-cors]]
            [ring.middleware.json :refer [wrap-json-body wrap-json-response]])
  
  (:import  [com.apelon.dts.client ServerConnectionEJB]
            [java.util Base64]))

However, when I try to execute this statement in the clj command line, it throws the following error:但是,当我尝试在 clj 命令行中执行此语句时,它会抛出以下错误:

Execution error (ClassNotFoundException) at java.net.URLClassLoader/findClass (URLClassLoader.java:445).
com.apelon.dts.client.ServerConnectionEJB.

I've checked the classpath using clj -Spath and the.jar file I am loading is in the classpath.我已经使用 clj -Spath 检查了类路径,我正在加载的 .jar 文件位于类路径中。 I have unzipped the jar file and verified that the files are where they should be for the:import directive in the ns declaration.我已经解压缩了 jar 文件并验证了这些文件是否位于 ns 声明中的 :import 指令应该位于的位置。 I have tried every incarnation of the filepath to the jar in my deps.edn file - local path, global path, forward slashes, backward slashes, etc. So far nothing has worked.我已经尝试了我的 deps.edn 文件中 jar 的文件路径的每个化身 - 本地路径、全局路径、正斜杠、反斜杠等。到目前为止,没有任何效果。

Does anyone have any idea what could cause the executor to not find the class and throw this error?有谁知道什么会导致执行程序找不到 class 并引发此错误? I'm past the point of hoping for a solution (though that would be nice) - I'm just looking for more theories to follow up on at this point我已经过了希望找到解决方案的地步(尽管那会很好)——此时我只是在寻找更多的理论来跟进

I use lein, not clj, but I can't imagine putting a jar file in a path named src could be correct.我使用 lein,而不是 clj,但我无法想象将 jar 文件放在名为src的路径中可能是正确的。 A quick look at the clj guide confirms that you're supposed to put it in deps , with a coordinate that specifies a local jar:快速查看clj 指南确认您应该将它放在deps中,坐标指定本地 jar:

 {:deps {db/driver {:local/root "/path/to/db/driver.jar"}}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM