Java ClassNotFoundException:org.eclipse.xtext.junit_2.4.3.v201309030823 找不到 junit.framework.TestCase
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21165915/
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
ClassNotFoundException: junit.framework.TestCase cannot be found by org.eclipse.xtext.junit_2.4.3.v201309030823
提问by Aaron Digulla
I'm puzzled by this error:
我对这个错误感到困惑:
java.lang.NoClassDefFoundError: junit/framework/TestCase
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:792)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.defineClass(DefaultClassLoader.java:188)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClassHoldingLock(ClasspathManager.java:638)
...
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:693)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:429)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main(RemotePluginTestRunner.java:62)
at org.eclipse.pde.internal.junit.runtime.CoreTestApplication.run(CoreTestApplication.java:23)
...
Caused by: java.lang.ClassNotFoundException: junit.framework.TestCase cannot be found by org.eclipse.xtext.junit_2.4.3.v201309030823
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:501)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 78 more
The exception happens when I run the tests for my Xtext DSL as plugin tests (i.e. when a new Eclipse platform is started internally). This happens beforeany of my code is executed.
当我将 Xtext DSL 的测试作为插件测试运行时(即在内部启动新的 Eclipse 平台时),会发生异常。这发生在我的任何代码执行之前。
When I look at the plugin dependencies, I can see that org.junit_4.11.0.v201303080030.jar
is on the classpath and I also see /.../workspace/.metadata/.plugins/org.eclipse.pde.core/.external_libraries/org.junit_4.11.0.v201303080030/junit.jar
当我查看插件依赖项时,我可以看到它org.junit_4.11.0.v201303080030.jar
在类路径上,我也看到了/.../workspace/.metadata/.plugins/org.eclipse.pde.core/.external_libraries/org.junit_4.11.0.v201303080030/junit.jar
So OSGis should definitely be able to resolve this dependency.
所以 OSGis 绝对应该能够解决这个依赖。
Does Xtext 2.4.3 work with JUnit 4.11 or do I have to downgrade my Eclipse install to JUnit 4.10?
Xtext 2.4.3 是否与 JUnit 4.11 一起工作,或者我是否必须将我的 Eclipse 安装降级到 JUnit 4.10?
采纳答案by A Paul
Two points
两点
First
第一的
Check your Project Properties->Java Build Path->Libraries (tab)
. JUnit should be there although this usually will show up in the build.
检查您的Project Properties->Java Build Path->Libraries (tab)
. JUnit 应该在那里,尽管这通常会出现在构建中。
Check you Project's Run Configurations->JUnit->Classpath (tab
). JUnit should be under User Entries for your project.
检查你的项目Run Configurations->JUnit->Classpath (tab
)。JUnit 应该在您的项目的用户条目下。
Second
第二
Check you have below plugins
检查你有以下插件
org.eclipse.xtext.xbase.junit
org.junit (3.8.2)
org.junit (4.8.2)
[EDIT]This got me on the right track. To fix the error make sure you have org.junit 3.8 in the target platform!
[编辑]这让我走上了正轨。要修复错误,请确保目标平台中有 org.junit 3.8 !
Explanation: The error above means that Eclipse itself couldn't start. It seems that the JUnit runner has a dependency on JUnit 3.8. It won't be used but without it, the whole platform can't be initialized.
说明:上述错误表示 Eclipse 本身无法启动。JUnit 运行器似乎依赖于 JUnit 3.8。它不会被使用,但没有它,整个平台无法初始化。
You can see whether you have the same problem by looking at the stack trace: Does it contain RemotePluginTestRunner.main
?
您可以通过查看堆栈跟踪来查看是否有相同的问题:是否包含RemotePluginTestRunner.main
?
To fix the error, add the org.junit 3.8 bundle to your target platform.
要修复错误,请将 org.junit 3.8 包添加到您的目标平台。
回答by Menachem
Two possible places to check for more details:
两个可能的地方可以检查更多详细信息:
- Decompile the jar you mentioned (
jar tvf
orjavap -classpath
and specify the JAR), and check for its dependecies - Check
eclipse.ini
for some initialization variables that could possibly be fixed.
- 反编译您提到的 jar(
jar tvf
或javap -classpath
指定 JAR),并检查其依赖关系 - 检查
eclipse.ini
一些可能修复的初始化变量。
回答by Aniruddh Joshi
Create a class with below code in your project-
在您的项目中使用以下代码创建一个类-
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class TestJunitLib {
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void test() {
fail("Not yet implemented");
}
}
On saving if eclipse shows compiler errors. Press Ctrl + 1 ( Quick Fix ) and select one of the below-
如果 Eclipse 显示编译器错误,则在保存时。按 Ctrl + 1 ( Quick Fix ) 并选择以下选项之一 -
a) Add jUnit 4 library to buildpath b) Fix project setup
a) 将 jUnit 4 库添加到 buildpath b) 修复项目设置
If a does not appear your eclipse installation is missing jUnit 4 plugin. In that case google up on how to install jUnit in eclipse.
如果没有出现,您的 eclipse 安装缺少 jUnit 4 插件。在这种情况下,谷歌搜索如何在 Eclipse 中安装 jUnit。
回答by Raju Rao
You may have have unresolved issues in your pom.xml file. Open the problems view solve accordingly. Then ideally you will be able to run the test cases successfully without encountering the classnotfoundexception.
您的 pom.xml 文件中可能存在未解决的问题。相应地打开问题视图解决。那么理想情况下,您将能够成功运行测试用例而不会遇到 classnotfoundexception。