使用来自 clojure 的 exiftool java 库

Using exiftool java library from clojure

我正在尝试在基于 leiningen 的 clojure 项目中包含用于 java 的 exiftool。这个库在 central 不可用,所以我在我的 project.clj 文件中包含了一个 :repository 标签。

project.clj:

(defproject clojure-mongo "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :repositories {"The Buzz Media Maven Repository" "http://maven.thebuzzmedia.com"}
  :dependencies [[org.clojure/clojure "1.7.0"]
                 [com.novemberain/monger "3.0.1"]
                 [com.thebuzzmedia/exiftool-lib "1.1"]])

用于 java 的 exiftool 不提供校验和,网站对此发出警告:

"NOTE: At this time we are not providing checksums for the files on our repository, so you will see '[WARNING] Checksum validation failed' messages from Maven, but they can be safely ignored."

果然,lein deps 给了我一个错误,虽然我不相信忽略它是安全的:

"正在从 The Buzz Media Maven 存储库中检索 com/thebuzzmedia/exiftool-lib/1.1/exiftool-lib-1.1.pom 无法传输工件 com.thebuzzmedia:exiftool-lib:pom:1.1 from/to Buzz Media Maven 存储库(http://maven.thebuzzmedia.com):校验和验证失败,存储库中没有可用的校验和

尝试在我的 clojure 代码中导入 ExifTool class 仍然给我一个 ClassNotFoundException。

core.clj:

(ns clojure-mongo.core
  (:require [monger.core :as mg]
            [monger.collection :as mc])
  (:import [com.mongodb MongoOptions ServerAddress]
           org.bson.types.ObjectId
           com.thebuzzmedia.exiftool-lib.ExifTool))

如何才能从 clojure 中访问此 class?

首先,您要导入的 class 是:

com.thebuzzmedia.exiftool.ExifTool

此外,默认情况下,如果校验和未通过验证,leiningen 将失败。您希望 :repositories 键看起来像这样:

:repositories [["The Buzz Media Maven Repository" 
               {:url "http://maven.thebuzzmedia.com"  :checksum :warn}]]

如果您愿意,也可以将其设置为 :ignore。见 sample leiningen project.