从类路径为 SUTime 初始化 JollyDayHoliday,ReflectionLoadingException:创建 TimeExpressionExtractorImpl 时出错

Initializing JollyDayHoliday for SUTime from classpath, ReflectionLoadingException: Error creating TimeExpressionExtractorImpl

我遇到了与 this 几乎相同的问题:

但是,就我而言,我正在使用 Clojure 构建 Web 应用程序,而我的同事正在使用 Java 构建我们的自然语言处理引擎。 NLP 作为一个 jar 包含在内。我们已经工作了几个星期,但我的同事添加了一些新的依赖项,这些依赖项现在给了我们这个错误。

这个人也报了类似的错误:

 Error creating edu.stanford.nlp.time.TimeExpressionExtractorImpl

参见here: with an answer here

这两种情况的问题似乎是不同库的版本冲突,但我不知道如何解决这个问题。在 Clojure 应用程序中,我们使用 clj-time,它显然使用 Joda-Time 2.6,而 Stanford Core NLP 库似乎使用 Joda 2.1。有没有办法解决这个冲突?

两个软件都可以编译,Clojure 应用程序可以启动,包括 NLP 引擎。但是,Clojure 应用随后会调用 NLP 引擎中的 "start" 方法,这会导致 NLP 引擎加载它需要的词法分析器和解析器。然后我们得到这些消息和错误:

Loading classifier from /home/safflower/apricots/dependencies/english.muc.7class.caseless.distsim.crf.ser.gz ... done [1.5 sec].

Loading parser from serialized file edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz ...  done [0.3 sec].

Loading parser from serialized file edu/stanford/nlp/models/lexparser/englishPCFG.caseless.ser.gz ...  done [1.1 sec].

Adding annotator tokenize

TokenizerAnnotator: No tokenizer type provided. Defaulting to PTBTokenizer.

Adding annotator ssplit

Adding annotator pos

Reading POS tagger model from edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger ... done [1.9 sec].

Adding annotator lemma

Adding annotator ner

Loading classifier from /home/safflower/apricots/dependencies/english.all.7class.distsim.crf.ser.gz ... done [1.5 sec].

Initializing JollyDayHoliday for SUTime from classpath: edu/stanford/nlp/models/sutime/jollyday/Holidays_sutime.xml as sutime.binder.1.
#<ReflectionLoadingException edu.stanford.nlp.util.ReflectionLoading$ReflectionLoadingException: Error creating edu.stanford.nlp.time.TimeExpressionExtractorImpl>

Exception in start/start: edu.stanford.nlp.util.ReflectionLoading$ReflectionLoadingException: Error creating edu.stanford.nlp.time.TimeExpressionExtractorImpl    

如果我在 Java 应用程序中执行此操作:

mvn dependency:tree

我看到了这个:

[INFO] |  +- joda-time:joda-time:jar:2.1:compile
[INFO] |  \- javax.xml.bind:jaxb-api:jar:2.2.7:compile
[INFO] +- log4j:log4j:jar:1.2.17:compile
[INFO] +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13:compile
[INFO] |  \- org.codehaus.jackson:jackson-core-asl:jar:1.9.13:compile
[INFO] +- junit:junit:jar:3.8.1:test
[INFO] +- net.sf.supercsv:super-csv:jar:2.0.0-beta-1:compile
[INFO] +- org.apache.commons:commons-lang3:jar:3.0:compile
[INFO] \- edu.stanford.nlp:stanford-corenlp:jar:3.5.2:compile
[INFO]    +- com.io7m.xom:xom:jar:1.2.10:compile
[INFO]    |  +- xml-apis:xml-apis:jar:1.3.03:compile
[INFO]    |  +- xerces:xercesImpl:jar:2.8.0:compile
[INFO]    |  \- xalan:xalan:jar:2.7.0:compile
[INFO]    +- com.googlecode.efficient-java-matrix-library:ejml:jar:0.23:compile
[INFO]    \- javax.json:javax.json-api:jar:1.0:compile

如果我在 Clojure 应用程序中这样做:

lein deps :tree

我看到了这个:

Retrieving org/clojure/tools.nrepl/0.2.6/tools.nrepl-0.2.6.pom from central
Retrieving clojure-complete/clojure-complete/0.2.3/clojure-complete-0.2.3.pom from clojars
Retrieving org/clojure/tools.nrepl/0.2.6/tools.nrepl-0.2.6.jar from central
Retrieving clojure-complete/clojure-complete/0.2.3/clojure-complete-0.2.3.jar from clojars
Possibly confusing dependencies found:
[slingshot "0.10.3"]
 overrides
[clj-http "1.1.2"] -> [slingshot "0.12.2" :exclusions [org.clojure/clojure]]

Consider using these exclusions:
[clj-http "1.1.2" :exclusions [slingshot]]

[clj-time "0.6.0"]
 overrides
[ring "1.4.0-RC1"] -> [ring/ring-jetty-adapter "1.4.0-RC1"] -> [ring/ring-core "1.4.0-RC1"] -> [clj-time "0.9.0"]
 and
[ring "1.4.0-RC1"] -> [ring/ring-devel "1.4.0-RC1"] -> [ring/ring-core "1.4.0-RC1"] -> [clj-time "0.9.0"]
 and
[ring "1.4.0-RC1"] -> [ring/ring-core "1.4.0-RC1"] -> [clj-time "0.9.0"]

Consider using these exclusions:
[ring "1.4.0-RC1" :exclusions [clj-time]]
[ring "1.4.0-RC1" :exclusions [clj-time]]
[ring "1.4.0-RC1" :exclusions [clj-time]]

[org.clojure/tools.namespace "0.2.4"]
 overrides
[ring "1.4.0-RC1"] -> [ring/ring-devel "1.4.0-RC1"] -> [ns-tracker "0.3.0"] -> [org.clojure/tools.namespace "0.2.10"]

Consider using these exclusions:
[ring "1.4.0-RC1" :exclusions [org.clojure/tools.namespace]]

[clj-stacktrace "0.2.7"]
 overrides
[ring "1.4.0-RC1"] -> [ring/ring-devel "1.4.0-RC1"] -> [clj-stacktrace "0.2.8"]

Consider using these exclusions:
[ring "1.4.0-RC1" :exclusions [clj-stacktrace]]

[clj-time "0.6.0"] -> [joda-time "2.2"]
 overrides
[ring "1.4.0-RC1"] -> [ring/ring-jetty-adapter "1.4.0-RC1"] -> [ring/ring-core "1.4.0-RC1"] -> [clj-time "0.9.0"] -> [joda-time "2.6"]
 and
[ring "1.4.0-RC1"] -> [ring/ring-devel "1.4.0-RC1"] -> [ring/ring-core "1.4.0-RC1"] -> [clj-time "0.9.0"] -> [joda-time "2.6"]
 and
[ring "1.4.0-RC1"] -> [ring/ring-core "1.4.0-RC1"] -> [clj-time "0.9.0"] -> [joda-time "2.6"]

Consider using these exclusions:
[ring "1.4.0-RC1" :exclusions [joda-time]]
[ring "1.4.0-RC1" :exclusions [joda-time]]
[ring "1.4.0-RC1" :exclusions [joda-time]]

 [cheshire "5.5.0"]
   [com.fasterxml.jackson.core/jackson-core "2.5.3"]
   [com.fasterxml.jackson.dataformat/jackson-dataformat-cbor "2.5.3"]
   [com.fasterxml.jackson.dataformat/jackson-dataformat-smile "2.5.3"]
   [tigris "0.1.1"]
 [clj-http "1.1.2"]
   [com.cognitect/transit-clj "0.8.271" :exclusions [[org.clojure/clojure]]]
     [com.cognitect/transit-java "0.8.287"]
       [com.fasterxml.jackson.datatype/jackson-datatype-json-org "2.3.2"]
         [com.fasterxml.jackson.core/jackson-databind "2.3.2"]
           [com.fasterxml.jackson.core/jackson-annotations "2.3.0"]
         [org.json/json "20090211"]
       [org.apache.directory.studio/org.apache.commons.codec "1.8"]
       [org.msgpack/msgpack "0.6.10"]
         [com.googlecode.json-simple/json-simple "1.1.1" :exclusions [[junit]]]
         [org.javassist/javassist "3.18.1-GA"]
   [commons-codec "1.10" :exclusions [[org.clojure/clojure]]]
   [commons-io "2.4" :exclusions [[org.clojure/clojure]]]
   [crouton "0.1.2" :exclusions [[org.clojure/clojure]]]
     [org.jsoup/jsoup "1.7.1"]
   [org.apache.httpcomponents/httpclient "4.4.1" :exclusions [[org.clojure/clojure]]]
     [commons-logging "1.2"]
   [org.apache.httpcomponents/httpcore "4.4.1" :exclusions [[org.clojure/clojure]]]
   [org.apache.httpcomponents/httpmime "4.4.1" :exclusions [[org.clojure/clojure]]]
   [org.clojure/tools.reader "0.9.2" :exclusions [[org.clojure/clojure]]]
   [potemkin "0.3.13" :exclusions [[org.clojure/clojure]]]
     [clj-tuple "0.2.1"]
 [clj-stacktrace "0.2.7"]
 [clj-time "0.6.0"]
   [joda-time "2.2"]
 [clojure-complete "0.2.3" :scope "test" :exclusions [[org.clojure/clojure]]]
 [com.novemberain/monger "2.0.1"]
   [clojurewerkz/support "1.1.0"]
     [com.google.guava/guava "18.0"]
   [org.mongodb/mongo-java-driver "2.12.4"]
 [com.taoensso/timbre "3.2.1"]
   [com.taoensso/encore "1.5.1"]
   [io.aviso/pretty "0.1.10"]
 [compojure "1.3.4"]
   [clout "2.1.2"]
     [instaparse "1.4.0" :exclusions [[org.clojure/clojure]]]
   [medley "0.6.0"]
   [org.clojure/tools.macro "0.1.5"]
   [ring/ring-codec "1.0.0"]
 [dire "0.5.1"]
   [robert/hooke "1.3.0"]
 [local/nlp "1.0-SNAPSHOT"]
 [manifold "0.1.0"]
   [org.clojure/tools.logging "0.3.1"]
   [riddley "0.1.9"]
 [me.raynes/fs "1.4.4"]
   [org.apache.commons/commons-compress "1.4"]
     [org.tukaani/xz "1.0"]
 [org.clojure/clojure "1.6.0"]
 [org.clojure/core.cache "0.6.4"]
   [org.clojure/data.priority-map "0.0.4"]
 [org.clojure/core.incubator "0.1.3"]
 [org.clojure/core.match "0.3.0-alpha4"]
   [org.clojure/tools.analyzer.jvm "0.6.5"]
     [org.clojure/core.memoize "0.5.6"]
     [org.clojure/tools.analyzer "0.6.4"]
     [org.ow2.asm/asm-all "4.2"]
 [org.clojure/data.json "0.2.5"]
 [org.clojure/tools.namespace "0.2.4"]
 [org.clojure/tools.nrepl "0.2.6" :scope "test" :exclusions [[org.clojure/clojure]]]
 [overtone/at-at "1.2.0"]
 [ring/ring-json "0.3.1"]
 [ring "1.4.0-RC1"]
   [ring/ring-core "1.4.0-RC1"]
     [commons-fileupload "1.3.1"]
     [crypto-equality "1.0.0"]
     [crypto-random "1.2.0"]
   [ring/ring-devel "1.4.0-RC1"]
     [hiccup "1.0.5"]
     [ns-tracker "0.3.0"]
       [org.clojure/java.classpath "0.2.2"]
   [ring/ring-jetty-adapter "1.4.0-RC1"]
     [org.eclipse.jetty/jetty-server "9.2.10.v20150310"]
       [javax.servlet/javax.servlet-api "3.1.0"]
       [org.eclipse.jetty/jetty-http "9.2.10.v20150310"]
         [org.eclipse.jetty/jetty-util "9.2.10.v20150310"]
       [org.eclipse.jetty/jetty-io "9.2.10.v20150310"]
   [ring/ring-servlet "1.4.0-RC1"]
 [slingshot "0.10.3"]

safflower@cloud-server-01:~/apricots$ 
   [robert/hooke "1.3.0"]
 [local/nlp "1.0-SNAPSHOT"]
 [manifold "0.1.0"]
   [org.clojure/tools.logging "0.3.1"]
   [riddley "0.1.9"]
 [me.raynes/fs "1.4.4"]
   [org.apache.commons/commons-compress "1.4"]
     [org.tukaani/xz "1.0"]
 [org.clojure/clojure "1.6.0"]
 [org.clojure/core.cache "0.6.4"]
   [org.clojure/data.priority-map "0.0.4"]
 [org.clojure/core.incubator "0.1.3"]
 [org.clojure/core.match "0.3.0-alpha4"]
   [org.clojure/tools.analyzer.jvm "0.6.5"]
     [org.clojure/core.memoize "0.5.6"]
     [org.clojure/tools.analyzer "0.6.4"]
     [org.ow2.asm/asm-all "4.2"]
 [org.clojure/data.json "0.2.5"]
 [org.clojure/tools.namespace "0.2.4"]
 [org.clojure/tools.nrepl "0.2.6" :scope "test" :exclusions [[org.clojure/clojure]]]
 [overtone/at-at "1.2.0"]
 [ring/ring-json "0.3.1"]
 [ring "1.4.0-RC1"]
   [ring/ring-core "1.4.0-RC1"]
     [commons-fileupload "1.3.1"]
     [crypto-equality "1.0.0"]
     [crypto-random "1.2.0"]
   [ring/ring-devel "1.4.0-RC1"]
     [hiccup "1.0.5"]
     [ns-tracker "0.3.0"]
       [org.clojure/java.classpath "0.2.2"]
   [ring/ring-jetty-adapter "1.4.0-RC1"]
     [org.eclipse.jetty/jetty-server "9.2.10.v20150310"]
       [javax.servlet/javax.servlet-api "3.1.0"]
       [org.eclipse.jetty/jetty-http "9.2.10.v20150310"]
         [org.eclipse.jetty/jetty-util "9.2.10.v20150310"]
       [org.eclipse.jetty/jetty-io "9.2.10.v20150310"]
   [ring/ring-servlet "1.4.0-RC1"]
 [slingshot "0.10.3"]

如何解决潜在的版本冲突?

这是我拥有的 project.clj 文件:

(defproject oyster "0.1"
  :dependencies [[org.clojure/clojure "1.6.0"]
                 [com.taoensso/timbre "3.2.1"]
                 [dire "0.5.1"]
                 [slingshot "0.10.3"]
                 [ring "1.4.0-RC1"]
                 [clj-time "0.6.0"]
                 [org.clojure/data.json "0.2.5"]
                 [compojure "1.3.4"]
                 [com.novemberain/monger "2.0.1"]
                 [org.clojure/tools.namespace "0.2.4"]
                 [manifold "0.1.0"]  
                 [me.raynes/fs "1.4.4"]
                 [org.clojure/core.incubator "0.1.3"]
                 [clj-stacktrace "0.2.7"]
                 [overtone/at-at "1.2.0"]
                 [ring/ring-json "0.3.1"]
                 [clj-http "1.1.2"]
                 [org.clojure/core.cache "0.6.4"]
                 [cheshire "5.5.0"]
                 [org.clojure/core.match "0.3.0-alpha4"]
                 [local/nlp "1.0-SNAPSHOT"]]
  :repositories {"local" ~(str (.toURI (java.io.File. "maven_repository")))}
  :disable-implicit-clean true
;;  :warn-on-reflection true
  :source-paths      ["src/clojure"]
  :java-source-paths ["src/java"]
  :main oyster.core
  :aot :all
  :jvm-opts ["-Xms100m" "-Xmx1000m" "-XX:-UseCompressedOops"])

包括您的 project.clj 将有助于找到问题。您可能需要在 project.clj

的 :dependencies 部分使用 :exclusions 选项

来自https://github.com/technomancy/leiningen/blob/master/sample.project.clj

;;; Dependencies, Plugins, and Repositories
  ;; Dependencies are listed as [group-id/name version]; in addition
  ;; to keywords supported by Pomegranate, you can use :native-prefix
  ;; to specify a prefix. This prefix is used to extract natives in
  ;; jars that don't adhere to the default "<os>/<arch>/" layout that
  ;; Leiningen expects.
  :dependencies [[org.clojure/clojure "1.3.0"]
                 [org.jclouds/jclouds "1.0" :classifier "jdk15"]
                 [net.sf.ehcache/ehcache "2.3.1" :extension "pom"]
                 [log4j "1.2.15" :exclusions [[javax.mail/mail :extension "jar"]
                                              [javax.jms/jms :classifier "*"]
                                              com.sun.jdmk/jmxtools
                                              com.sun.jmx/jmxri]]
                 [org.lwjgl.lwjgl/lwjgl "2.8.5"]
                 [org.lwjgl.lwjgl/lwjgl-platform "2.8.5"
                  :classifier "natives-osx"
                  ;; LWJGL stores natives in the root of the jar; this
                  ;; :native-prefix will extract them.
                  :native-prefix ""]]

在我的一个项目中,我遇到了与您类似的问题,我需要这一行:

[com.datomic/datomic-pro  "0.9.5173" :exclusions [joda-time]]