【发布时间】:2017-11-21 23:13:44
【问题描述】:
我在本地克隆了 joda-time GitHub 存储库,将它作为 Eclipse 和 IntelliJ Idea 中的 Maven 项目导入,它在两个 IDE 中构建得非常好。但是当尝试运行 JUnit 测试时,它在任何一个 IDE 中都不起作用,我看不出问题出在哪里。
我知道我需要创建一个额外的文件夹
src\tz-data\org\joda\time\tz\data
把这两个文件放在那里
CET
ZoneInfoMap
我已经做到了。
JUnit 测试仍然没有运行,有趣的是我在 Eclipse 下得到了完全不同的错误:
java.lang.ExceptionInInitializerError
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.getTest(JUnit3TestLoader.java:100)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.loadTests(JUnit3TestLoader.java:51)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.IllegalArgumentException: The datetime zone id 'Europe/Paris' is not recognised
at org.joda.time.DateTimeZone.forID(DateTimeZone.java:234)
at org.joda.time.TestLocalDate_Basics.<clinit>(TestLocalDate_Basics.java:50)
... 10 more
在 IntelliJ Idea 下:
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.joda.time.TestAbstractPartial
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at junit.framework.TestSuite.createTest(TestSuite.java:58)
at junit.framework.TestSuite.addTestMethod(TestSuite.java:280)
at junit.framework.TestSuite.<init>(TestSuite.java:140)
at com.intellij.junit3.TestRunnerUtil.createClassOrMethodSuite(TestRunnerUtil.java:147)
at com.intellij.junit3.TestAllInPackage2.<init>(TestAllInPackage2.java:32)
at com.intellij.junit3.TestRunnerUtil.getTestSuite(TestRunnerUtil.java:78)
at com.intellij.junit3.JUnit3IdeaTestRunner.startRunnerWithArgs(JUnit3IdeaTestRunner.java:43)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
非常感谢任何有关如何解决此问题的提示。
【问题讨论】:
-
查看他们的 pom.xml 它依赖于 exec 插件来调用 org.joda.time.tz.ZoneInfoCompiler 并生成一些文件。在 intellij 中,我进入了 maven 栏并运行了生命周期的编译步骤,之后单元测试开始工作。
-
谢谢罗比,你是对的。我终于想通了... :)
标签: eclipse intellij-idea junit jodatime