maven项目Junit单元测试java.lang.ClassNotFoundException解决
2017-05-14 22:46
686 查看
问题描述
maven创建的项目,通过run as maven build启动后,测试类统统出现Class not found异常,有时候打开eclipse直接调试测试类的时候又是好好的,有时候maven build以后就出问题Class not found zyh.controller.TestPageHelper
java.lang.ClassNotFoundException: zyh.controller.TestPageHelper
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:685)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
解决办法
方法1:maven build的命令,只用tomcat7:run就行了(根据你的tomcat的版本来,我在配置里用的7),前面就不要加clean了,因为你每次clean了,编译出来的测试类的文件就被清除了。这样,不论你是否build了maven工程,进行Junit单元测试都不会受影响方法2:maven build的命令如果是 clean tomcat7:run,那么你要进行Junit单元测试的时候,你的测试类就需要重新编译,方法就是在你的测试类里面随便找个位置敲个空格或者在哪里随便enter一行,然后C
4000
trl+S进行保存,这下你就有了编译后的文件。现在进行你的单元测试吧。
相关文章推荐
- Maven项目下 java.lang.ClassNotFoundException 常规解决办法
- Maven项目下java.lang.ClassNotFoundException常规解决办法
- Maven项目下报错误java.lang.ClassNotFoundException的解决办法
- MyEclipse重新导入Maven项目后启动服务器报java.lang.ClassNotFoundException错误解决办法
- maven项目启动报:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener 错误解决方法-杜恩德
- Maven项目下java.lang.ClassNotFoundException常规解决办法
- Maven项目下java.lang.ClassNotFoundException常规解决办法
- 启动maven项目报错:java.lang.ClassNotFoundException: ContextLoaderListener解决方法
- Maven项目下java.lang.ClassNotFoundException常规解决办法 (很急人的)
- Maven项目下 java.lang.ClassNotFoundException 常规解决的方法
- Maven项目下java.lang.ClassNotFoundException常规解决办法
- maven创建spring项目之后,启动报错java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoade
- 真正解决问题:maven eclipse tomcat java.lang.ClassNotFoundException: org.springframework.web.context.Contex
- maven 项目出现 java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
- maven 项目出现 java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
- Maven工程启动报错:maven 项目出现 java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoad
- maven web 项目中启动报错java.lang.ClassNotFoundException: org.springframework.web.util.Log4jConfigListener
- maven项目 启动报错:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
- maven项目 无法运行main方法的问题。java.lang.ClassNotFoundException
- maven项目 启动报错:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener