使用 Scala 使用 Joda Time 对错误进行分类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13856266/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 04:47:46  来源:igfitidea点击:

Class broken error with Joda Time using Scala

scalasbtjodatime

提问by Hyman

I'm adding the Joda Time repository to SBT with

我正在将 Joda Time 存储库添加到 SBT

libraryDependencies ++= Seq(
  "joda-time"         % "joda-time"           % "2.1"
)

Then I merrily use it like this:

然后我愉快地使用它:

 val ymd = org.joda.time.format.DateTimeFormat.forPattern("yyyyMMdd")
  ymd.parseDateTime("20121212")

But, when I compile the project in SBT, I get a nasty:

但是,当我在 SBT 中编译项目时,我得到了一个讨厌的信息:

[warn] Class org.joda.convert.FromString not found - continuing with a stub.
[warn] Caught: java.lang.NullPointerException while parsing annotations in /home/Hyman/.ivy2/cache/joda-time/joda-time/jars/joda-time-2.1.jar(org/joda/time/DateTime.class)
[error] error while loading DateTime, class file '/home/Hyman/.ivy2/cache/joda-time/joda-time/jars/joda-time-2.1.jar(org/joda/time/DateTime.class)' is broken
[error] (class java.lang.RuntimeException/bad constant pool tag 10 at byte 42)

I tried the 2.0 version of joda-time, but get the same error.

我尝试了 joda-time 的 2.0 版本,但得到同样的错误。

回答by David Pierre

Add this dependency:

添加此依赖项:

"org.joda" % "joda-convert" % "1.8.1"

“org.joda”%“joda-convert”%“1.8.1”

It's an optional dependency of joda-time. I had to add it in my own project for the scala compiler to accept working with the joda-time jar.

它是 joda-time 的可选依赖项。我必须将它添加到我自己的项目中,以便 Scala 编译器接受使用 joda-time jar。

Your issue seems to be the same.

你的问题似乎是一样的。

Version is as at time of editing, latest versions can be found here

版本与编辑时相同,最新版本可以在这里找到

回答by mn2013

I was running into a similar issue:

我遇到了类似的问题:

[warn] Class net.jcip.annotations.NotThreadSafe not found - continuing with a stub.
[warn] Caught: java.lang.NullPointerException while parsing annotations in ~/.ivy2-p2/cache/org.opensaml/xmltooling/jars/xmltooling-1.3.4.jar(org/opensaml/xml/util/IDIndex.class)
[error] error while loading AttributeMap, class file '~/.ivy2-p2/cache/org.opensaml/xmltooling/jars/xmltooling-1.3.4.jar(org/opensaml/xml/util/AttributeMap.class)' is broken
[error] (class java.lang.RuntimeException/bad constant pool index: 0 at pos: 12058)

Explicitly adding a dependency jcip-annotations-1.0.jarresolved the issue.

显式添加依赖项jcip-annotations-1.0.jar解决了该问题。