java.lang.NoClassDefFoundError: org/junit/runner/manipulation/Filter
今天想写个随笔,最近经常遇到使用junit的时候报java.lang.NoClassDefFoundError,今天算是恍然大悟了,原来junit虽然在gradle里面配置了,也在Project and External Dependencies中看到了junit的jar包,并能在这个junit的jar包里面找到org/junit/runner/manipulation/Filter这个类,但是run as junit test的时候就偏偏要报java.lang.NoClassDefFoundError: org/junit/runner/manipulation/Filter。

以为是gradle配置问题,testImplementation、implementation、api都不行
后来想想,出现这种情况无外乎gradle中引入的jar包(即Project and External Dependencies中的jar包)在run as junit test的时候并没有被jvm加载,所以才会出现这种现象,解决办法就是在build path 中add library,加入junit
下面附上在main里面打出已加载的class:
package proxy; import java.lang.reflect.Field;
import java.lang.reflect.Proxy;
import java.util.Vector; import org.junit.Test; /**
* Created by 136187300@qq.com on 2018年6月9日.
*/ public class TestProxy { @Test
public void test1() { TestLog testLog = new TestLogImpl();
TestLogInterceptor testLogInterceptor = new TestLogInterceptor();
testLogInterceptor.setTarget(testLog);
TestLog proxy = (TestLog)Proxy.newProxyInstance(testLog.getClass().getClassLoader()
, testLog.getClass().getInterfaces(), testLogInterceptor);
proxy.print();
} public static void main(String[] args) {
TestLog testLog = new TestLogImpl();
TestLogInterceptor testLogInterceptor = new TestLogInterceptor();
testLogInterceptor.setTarget(testLog);
TestLog proxy = (TestLog)Proxy.newProxyInstance(testLog.getClass().getClassLoader()
, testLog.getClass().getInterfaces(), testLogInterceptor);
proxy.print();
try {
new TestProxy().printClass();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} public void printClass() throws Exception {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Class cla = classLoader.getClass();
while (cla != ClassLoader.class)
cla = cla.getSuperclass();
Field field = cla.getDeclaredField("classes");
field.setAccessible(true);
Vector v = (Vector) field.get(classLoader);
for (int i = 0; i < v.size(); i++) {
System.out.print(((Class)v.get(i)).getName()+",");
if(i%10 == 0)System.out.println("");
}
}
}
java.lang.NoClassDefFoundError: org/junit/runner/manipulation/Filter的更多相关文章
- 就没有我遇不到的报错!java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/filter/Filter
本来准备用HBase的Bulkload将HDFS的HFile文件导入到HBase的myuser2表中,用的是yarn jar的命令 yarn jar /export/servers/hbase-1.2 ...
- java.lang.NoClassDefFoundError: org/junit/rules/TestRule
错误原因:通过定位发现是找不到TestRule这个类,检查项目引用的Junit版本为4.7,发现TestRule是在Junit版本4.10后添加的新特性 解决方法:把junit版本由4.7改成4.10
- 【Junit】JUnit-4.12使用报java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing错误
下载了最新的JUnit版本,是4.12,结果尝试使用发现总是报java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing这样的错误, 上网查 ...
- 【JUnit 报错】java.lang.NoClassDefFoundError: org/apache/logging/log4j/message/Message
使用JUnit的时候,报错:java.lang.NoClassDefFoundError: org/apache/logging/log4j/message/Message 原因是因为项目中导入的架包 ...
- Exception starting filter struts2 java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor
按教程,使用Convention插件进行配置 教程中说只要加入struts2-convention-plugin-2.3.4.1.jar这个jar包就可以使用. 按照这种方法部署后,启动tomcat报 ...
- SSH整合后tomcat启动报错SEVERE: Exception starting filter struts2 java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor
错误信息: SEVERE: Exception starting filter struts2 java.lang.NoClassDefFoundError: org/objectweb/asm/C ...
- HTTP Status 500 - javax.servlet.ServletException: java.lang.NoClassDefFoundError: junit/framework/Test解决方法
java代码 package webViewer; import java.io.*; import junit.framework.Test; import com.aspose.words.*; ...
- Java AOP nested exception is java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice || Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#0' 两个异常解决办法
贴出applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans ...
- 异常:Caused by: java.lang.NoClassDefFoundError: Could not initialize class net.sf.log4jdbc.Properties
参考文章: 使用Log4jdbc-log4j2监听MyBatis中运行的SQL和Connection 使用 log4jdbc格式化输出SQL,maven配置如下: <dependency> ...
随机推荐
- Linux内核设计与实现 第三章
1. 进程和线程 进程和线程是程序运行时状态,是动态变化的,进程和线程的管理操作都是由内核来实现的. Linux中的进程于Windows相比是很轻量级的,而且不严格区分进程和线程,线程不过是一种特殊的 ...
- Linux实践三:程序破解
一.汇编指令机器码 二.反汇编与十六进制编程器 三.可执行文件的基本格式 hexdump -x login 用16进制数字显示login内容 objdump -x login 显示login中各个段以 ...
- vuejs基础
**### 数据与方法 // 我们的数据对象 var data = { a: 1 } // 该对象被加入到一个 Vue 实例中 var vm = new Vue({ data: data }) // ...
- Docker Volume
http://www.cnblogs.com/sammyliu/p/5932996.html http://dockone.io/article/128
- Docker中安装Nexus3
https://blog.csdn.net/sqandczm/article/details/78560710 https://hub.docker.com/r/sonatype/nexus/ htt ...
- 键盘事件(keyup、keydown、keypress)
1.onkeyup 和onkeydown时,keyCode是不区分大小写的,会将小写字母自动转化为大写字母. 2 onkeypress时,区分大小写. 3兼容event.keyCode||event. ...
- Oracle 数据库启动过程
一 启动数据库 Oracle启动过程涉及几种模式,这些模式涉及不同的文件,每个状态下数据库做不同的事情,同时这些模式适用于不同的维护需求,主要的模式有三种:NOMOUNT.MOUNT.OPEN. 1 ...
- Qt__QWidget::update()与Qwidget::repaint()的区别
QT事件的产生 1.操作系统产生 操作系统将获取的事件,比如鼠标按键,键盘按键等keyPressEvent,keyReleaseEvent,mousePressEvent,mouseReleaseEv ...
- laravel5 报错419,form 添加crrf_field 后让然失败,本地环境配置问题
这个是因为laravel自带CSRF验证的问题 解决方法 方法一:去关掉laravel的csrf验证,但这个人不建议,方法也不写出来了. 方法二:把该接口写到api.php上就好了 方法三: 首先在页 ...
- ubuntu更改分辨率
1. 输入:$cvt 1920 1080 2 输入: $xrandr 3 输入: $sudo xrandr --newmode "1920x1080_60.00" 173.00 1 ...