简体   繁体   中英

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). My project file is at C:\Users\fadrian\Projects\motive-cql-builder\mercator-server. My deps.edn file is in this folder and looks like this:

{: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. It is called ServerConnectionEJB.class. I have verified that the file is in this location in the jarfile.

The ns statement in my code file is this:

(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:

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. I have unzipped the jar file and verified that the files are where they should be for the:import directive in the ns declaration. 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.

Does anyone have any idea what could cause the executor to not find the class and throw this error? 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. 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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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