Maven构建在运行时抛出JodaTime异常

时间:2014-01-31 18:31:33

标签: java maven jodatime stanford-nlp

我正在使用corenlp 3.3.1构建基于maven的java应用程序。

突出的pom.xml依赖项是

        <dependency>
            <groupId>edu.stanford.nlp</groupId>
            <artifactId>stanford-corenlp</artifactId>
            <version>3.3.1</version>
        </dependency>

        <dependency>
            <groupId>edu.stanford.nlp</groupId>
            <artifactId>stanford-corenlp</artifactId>
            <version>3.3.1</version>
            <classifier>models</classifier>
        </dependency>

运行

 mvn dependency:tree

给出:

[INFO] +- log4j:log4j:jar:1.2.17:compile
[INFO] +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] +- edu.stanford.nlp:stanford-corenlp:jar:3.3.1: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] |  +- joda-time:joda-time:jar:2.1:compile
[INFO] |  +- de.jollyday:jollyday:jar:0.4.7:compile
[INFO] |  |  \- javax.xml.bind:jaxb-api:jar:2.2.7:compile
[INFO] |  \- com.googlecode.efficient-java-matrix-library:ejml:jar:0.23:compile
[INFO] \- edu.stanford.nlp:stanford-corenlp:jar:models:3.3.1:compile

我的代码包括:

Properties props = new Properties();
            props.put("annotators",
                    "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
            this.pipeline = new StanfordCoreNLP(props);

这样做之后会引发异常:

Adding annotator tokenize
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.2 sec].
Adding annotator lemma
Adding annotator ner
Loading classifier from edu/stanford/nlp/models/ner/english.all.3class.distsim.crf.ser.gz ... done [4.8 sec].
Loading classifier from edu/stanford/nlp/models/ner/english.muc.7class.distsim.crf.ser.gz ... done [2.3 sec].
Loading classifier from edu/stanford/nlp/models/ner/english.conll.4class.distsim.crf.ser.gz ... done [3.8 sec].

例外是

java.lang.NoSuchMethodError: org.joda.time.Duration.compareTo(Lorg/joda/time/ReadableDuration;)I
    at edu.stanford.nlp.time.SUTime$Duration.compareTo(SUTime.java:3671)
    at edu.stanford.nlp.time.SUTime$Duration.max(SUTime.java:3753)
    at edu.stanford.nlp.time.SUTime$Time.difference(SUTime.java:1434)
    at edu.stanford.nlp.time.SUTime$Range.<init>(SUTime.java:4072)
    at edu.stanford.nlp.time.SUTime.<clinit>(SUTime.java:655)
    at edu.stanford.nlp.time.EnglishTimeExpressionPatterns.initTimeUnitsMap(EnglishTimeExpressionPatterns.java:1542)
    at edu.stanford.nlp.time.EnglishTimeExpressionPatterns.<init>(EnglishTimeExpressionPatterns.java:47)
    at edu.stanford.nlp.time.TimeExpressionExtractorImpl.init(TimeExpressionExtractorImpl.java:65)
    at edu.stanford.nlp.time.TimeExpressionExtractorImpl.<init>(TimeExpressionExtractorImpl.java:37)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at java.lang.Class.newInstance(Class.java:374)
    at edu.stanford.nlp.time.TimeExpressionExtractorFactory.create(TimeExpressionExtractorFactory.java:45)
    at edu.stanford.nlp.time.TimeExpressionExtractorFactory.createExtractor(TimeExpressionExtractorFactory.java:28)
    at edu.stanford.nlp.ie.regexp.NumberSequenceClassifier.<init>(NumberSequenceClassifier.java:79)
    at edu.stanford.nlp.ie.NERClassifierCombiner.<init>(NERClassifierCombiner.java:67)
    at edu.stanford.nlp.pipeline.StanfordCoreNLP$6.create(StanfordCoreNLP.java:619)
    at edu.stanford.nlp.pipeline.AnnotatorPool.get(AnnotatorPool.java:81)
    at edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(StanfordCoreNLP.java:260)
    at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:127)
    at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:123)
    at com.othermaps.analysis.madhatter.service.ServiceImpl.initTAEngines(ServiceImpl.java:49)
    ... 34 more

我假设这是一个'错误的JodaTime版本'问题 - 但是如果我从corenlp的依赖关系中明确地排除了JodaTime工件,我找不到不生成此Exception的版本: / p>

<dependency>
    <groupId>edu.stanford.nlp</groupId>
    <artifactId>stanford-corenlp</artifactId>
    <version>3.3.1</version>
        <exclusions>
            <exclusion>
                <groupId>joda-time</groupId>
                <artifactId>joda-time</artifactId>
            </exclusion>
        </exclusions>
</dependency>

并手动添加显式定义的版本

例如

<dependency>
    <groupId>joda-time</groupId>
    <artifactId>joda-time</artifactId>
    <version>2.1</version>
</dependency>

(是的,我知道这与自动添加的依赖项版本相同:这只是我尝试过的一个例子; - )

所有帮助表示赞赏。

d

1 个答案:

答案 0 :(得分:1)

我的最后一条评论包含答案 - 它与CXF包中包含的Joda jar冲突。