java.lang.ClassNotFoundException与java.lang.NoClassDefFoundError的区别(转)
ClassNotFoundException
ClassNotFoundException这个错误,比较常见也好理解。
原因:就是找不到指定的class。
常见的场景就是:
1 调用class的forName方法时,找不到指定的类
2 ClassLoader 中的 findSystemClass() 方法时,找不到指定的类
3 ClassLoader 中的 loadClass() 方法时,找不到指定的类
java.lang.Class.java:
/**
* Returns the <code>Class</code> object associated with the class or
* interface with the given string name. Invoking this method is
* equivalent to:
*
* <blockquote><pre>
* Class.forName(className, true, currentLoader)
* </pre></blockquote>
*
* where <code>currentLoader</code> denotes the defining class loader of
* the current class.
*
* <p> For example, the following code fragment returns the
* runtime <code>Class</code> descriptor for the class named
* <code>java.lang.Thread</code>:
*
* <blockquote><pre>
* Class t = Class.forName("java.lang.Thread")
* </pre></blockquote>
* <p>
* A call to <tt>forName("X")</tt> causes the class named
* <tt>X</tt> to be initialized.
*
* @param className the fully qualified name of the desired class.
* @return the <code>Class</code> object for the class with the
* specified name.
* @exception LinkageError if the linkage fails
* @exception ExceptionInInitializerError if the initialization provoked
* by this method fails
* @exception ClassNotFoundException if the class cannot be located
*/
public static Class<?> forName(String className)
throws ClassNotFoundException {
return forName0(className, true, ClassLoader.getCallerClassLoader());
}
/** Called after security checks have been made. */
private static native Class forName0(String name, boolean initialize,
ClassLoader loader)
throws ClassNotFoundException;
NoClassDefFoundError
这个就比较奇葩了,查找其他的资料是说,通过了编译,但是使用的时候,比如new的时候会出错。
通过查找资料,搜集到如下的场景:
1 类依赖的class或者jar不存在
2 类文件存在,但是存在不同的域中
3 大小写问题,javac编译的时候是无视大小的,很有可能你编译出来的class文件就与想要的不一样!这个没有做验证。

http://www.cnblogs.com/xing901022/p/4185514.html
java.lang.ClassNotFoundException与java.lang.NoClassDefFoundError的区别(转)的更多相关文章
- java.lang.ClassNotFoundException与java.lang.NoClassDefFoundError的区别
java.lang.ClassNotFoundException与java.lang.NoClassDefFoundError的区别 以前一直没有注意过这个问题,前两天机缘巧合上网查了一下,然后自 ...
- Caused by: java.lang.ClassNotFoundException: org.aspectj.lang.annotation.Around
1.错误描述 INFO:2015-05-01 11:12:15[localhost-startStop-1] - Root WebApplicationContext: initialization ...
- SpringMVC集成AOP错误:java lang classnotfoundexception org aspectj lang joinpoint
记录自己出现的问题,Spring AOP 使用测试类测试没问题,在SpringMVC启动服务器时出现java lang classnotfoundexception org aspectj lang ...
- java.lang.ClassNotFoundException和java.lang.NoClassDefFoundError的区别
java里生成对象有如下两种方式: 1: Object obj = new ClassName(); 直接new一个对象 2: Class clazz = Class.forName(ClassNam ...
- Java基础学习(一)---Java初识
一.Java介绍 关于Java的诞生和发展网上比较多,在此就不再赘述了,可以参考http://i.cnblogs.com/EditArticles.aspx?postid=4050233. 1.1 J ...
- java.lang.ClassNotFoundException: net.sf.json.JSONArray,java.lang.NoClassDefFoundError: net/sf/json/JSONArray jetty跑项目遇到的问题
2016-05-18 15:44:25 ERROR Dispatcher.error[user:|url:]:L38 - Dispatcher initialization failed Unable ...
- Could not load resource factory class [Root exception is java.lang.ClassNotFoundException: org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory]
WARNING: Failed to register in JMX: javax.naming.NamingException: Could not load resource factory cl ...
- java.lang.ClassNotFoundException: org.hibernate.annotations.common.reflection.MetadataProvider
Caused by: java.lang.NoClassDefFoundError: org/hibernate/annotations/common/reflection/MetadataProvi ...
- java.lang.ClassNotFoundException: javax.persistence.EntityListeners
Exception in thread "main" java.lang.NoClassDefFoundError: javax/persistence/EntityListene ...
随机推荐
- java:字符串的“+”运算
今天在一篇博客里,意外的看到了一段关于java中对字符串的“+”运算的处理(博客原文:http://blog.csdn.net/yirentianran/article/details/2871417 ...
- 转:FileReader详解与实例---读取并显示图像文件
~~~针对需要读取本地图像,并立即显示在浏览器的情况,由于chrome firefox出于安全限制,input file并不返回文件的真实路径,经测试IE6/7/8都会返回真实路径,所以chrome, ...
- spring Annotation 笔记2.1
使用注解替代xml 在前几章的笔记基础上添加使用注解的形式 1.配置applicationContext 添加context schema <?xml version="1.0&quo ...
- hibernate HQL查询 2.2
hql(都要在事务中完成)session.beginTransaction();session.getTransaction().commit(); session.beginTransaction( ...
- Linux 终端部分重要快捷键
tab 自动补全文件名,目录名或命令名ctrl+c 强行终止当前程序Ctrl+d 键盘输入结束或退出终端 Ctrl+s 暂定当前程序,暂停后按下任意键恢复运行 Ctrl+z 将当前程序放到后台运行 ...
- CursorAdapter说明
参考:http://www.bubuko.com/infodetail-734550.html和http://blog.csdn.net/yuzhiboyi/article/details/76548 ...
- 【redis】windows
官方网站:http://www.redis.io 百度百科:http://baike.baidu.com/view/4595959.htm?fr=aladdin windows下安装redis: 下载 ...
- c.Tom and paper
Tom and paper Description There is a piece of paper in front of Tom, its length and width are intege ...
- [HDU 1973]--Prime Path(BFS,素数表)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1973 Prime Path Time Limit: 5000/1000 MS (Java/Others ...
- 2057 A + B Again
A + B Again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...