NoClassDefFoundError 问题原因1:缺少jar包
创新互联建站主要为客户提供服务项目涵盖了网页视觉设计、VI标志设计、网络营销推广、网站程序开发、HTML5响应式成都网站建设、成都手机网站制作、微商城、网站托管及网站维护、WEB系统开发、域名注册、国内外服务器租用、视频、平面设计、SEO优化排名。设计、前端、后端三个建站步骤的完善服务体系。一人跟踪测试的建站服务标准。已经为成都假山制作行业客户提供了网站维护服务。
首先最常见的原因是classpath的配置问题。例子程序:
本例子程序尝试创建一个新的CallerClassA实例,然后执行他的一个方法,此方法引用了类ReferencingClassA,本例子演示了classpath问题导致的NoClassDefFoundError ,本例子还打印了当前的classloader chain的情况,以便进一步的分析。这个打印信息对你以后分析此类问题也很有帮助的:
程序
Java代码 收藏代码
public class NoClassDefFoundErrorSimulator {
public static void main(String[] args) {
System.out
.println("java.lang.NoClassDefFoundError Simulator");
// Print current Classloader context
System.out.println("\nCurrent ClassLoader chain: "
+ ClassloaderUtil.getCurrentClassloaderDetail());
// 1. Create a new instance of CallerClassA
CallerClassA caller = new CallerClassA();
// 2. Execute method of the caller
caller.doSomething();
System.out.println("done!");
}
}
Java代码 收藏代码
public class CallerClassA {
private final static String CLAZZ = CallerClassA.class.getName();
static {
System.out.println("Classloading of " + CLAZZ + " in progress..."
+ ClassloaderUtil.getCurrentClassloaderDetail());
}
public CallerClassA() {
System.out.println("Creating a new instance of "
+ CallerClassA.class.getName() + "...");
}
public void doSomething() {
// Create a new instance of ReferencingClassA
ReferencingClassA referencingClass = new ReferencingClassA();
}
}
Java代码 收藏代码
public class ReferencingClassA {
private final static String CLAZZ = ReferencingClassA.class.getName();
static {
System.out.println("Classloading of " + CLAZZ + " in progress..."
+ ClassloaderUtil.getCurrentClassloaderDetail());
}
public ReferencingClassA() {
System.out.println("Creating a new instance of "
+ ReferencingClassA.class.getName() + "...");
Maps.newHashMap();
}
public void doSomething() {
// nothing to do...
}
}
打印classloader工具类:
Java代码 收藏代码
public class ClassloaderUtil {
public static String getCurrentClassloaderDetail() {
StringBuffer classLoaderDetail = new StringBuffer();
StackClassLoader classLoaderStack = new StackClassLoader();
ClassLoader currentClassLoader = Thread.currentThread()
.getContextClassLoader();
classLoaderDetail
.append("\n-----------------------------------------------------------------\n");
// Build a Stack of the current ClassLoader chain
while (currentClassLoader != null) {
classLoaderStack.push(currentClassLoader);
currentClassLoader = currentClassLoader.getParent();
}
// Print ClassLoader parent chain
while (classLoaderStack.size() 0) {
ClassLoader classLoader = classLoaderStack.pop();
// Print current
classLoaderDetail.append(classLoader);
if (classLoaderStack.size() 0) {
classLoaderDetail.append("\n--- delegation ---\n");
} else {
classLoaderDetail.append(" **Current ClassLoader**");
}
}
classLoaderDetail
.append("\n-----------------------------------------------------------------\n");
return classLoaderDetail.toString();
}
}
正常运行:
Java代码 收藏代码
java -classpath .;../guava-12.0.jar NoClassDefFoundError.NoClassDefFoundErrorSimulator
java.lang.NoClassDefFoundError Simulator
Current ClassLoader chain:
-----------------------------------------------------------------
sun.misc.Launcher$ExtClassLoader@addbf1
--- delegation ---
sun.misc.Launcher$AppClassLoader@19821f **Current ClassLoader**
-----------------------------------------------------------------
Classloading of NoClassDefFoundError.CallerClassA in progress...
-----------------------------------------------------------------
sun.misc.Launcher$ExtClassLoader@addbf1
--- delegation ---
sun.misc.Launcher$AppClassLoader@19821f **Current ClassLoader**
-----------------------------------------------------------------
Creating a new instance of NoClassDefFoundError.CallerClassA...
Classloading of NoClassDefFoundError.ReferencingClassA in progress...
-----------------------------------------------------------------
sun.misc.Launcher$ExtClassLoader@addbf1
--- delegation ---
sun.misc.Launcher$AppClassLoader@19821f **Current ClassLoader**
-----------------------------------------------------------------
Creating a new instance of NoClassDefFoundError.ReferencingClassA...
done!
异常重现:
Java代码 收藏代码
java -classpath . NoClassDefFoundError.NoCl
java.lang.NoClassDefFoundError Simulator
Current ClassLoader chain:
-----------------------------------------------------------------
sun.misc.Launcher$ExtClassLoader@addbf1
--- delegation ---
sun.misc.Launcher$AppClassLoader@19821f **Current ClassLoader**
-----------------------------------------------------------------
Classloading of NoClassDefFoundError.CallerClassA in progress...
-----------------------------------------------------------------
sun.misc.Launcher$ExtClassLoader@addbf1
--- delegation ---
sun.misc.Launcher$AppClassLoader@19821f **Current ClassLoader**
-----------------------------------------------------------------
Creating a new instance of NoClassDefFoundError.CallerClassA...
Classloading of NoClassDefFoundError.ReferencingClassA in progress...
-----------------------------------------------------------------
sun.misc.Launcher$ExtClassLoader@addbf1
--- delegation ---
sun.misc.Launcher$AppClassLoader@19821f **Current ClassLoader**
-----------------------------------------------------------------
Creating a new instance of NoClassDefFoundError.ReferencingClassA...
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/Maps
at NoClassDefFoundError.ReferencingClassA.init(ReferencingClassA.java:28)
at NoClassDefFoundError.CallerClassA.doSomething(CallerClassA.java:31)
at NoClassDefFoundError.NoClassDefFoundErrorSimulator.main(NoClassDefFoundErrorSimulator.jav
Caused by: java.lang.ClassNotFoundException: com.google.common.collect.Maps
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 3 more
发生了什么?当你在classpath中不包含guava的引用的时候,由于ReferencingClassA在运行期引用了此类,导致了classloader报告找不到此类,从而出现NoClassDefFoundError。
classloader分析
注意:
Java代码 收藏代码
Classloading of NoClassDefFoundError.CallerClassA in progress...
-----------------------------------------------------------------
sun.misc.Launcher$ExtClassLoader@addbf1
--- delegation ---
sun.misc.Launcher$AppClassLoader@19821f **Current ClassLoader**
-------------------------
sun.misc.Launcher$AppClassLoader是系统的classloader,负责根据classpath设置在启动的时候加载应用需要的class。
sun.misc.Launcher$ExtClassLoader是扩展classloader,负责从java_home/lib/etc以及其他使用java.ext.dirs配置的目录从加载扩展java class。
从打印结果可以看出,sun.misc.Launcher$ExtClassLoader是系统classloader的实际父类。
建议处理策略
分析异常堆栈,找到缺少的java类名称,在classpath中验证,确保编译和运行期都能找到此类。
添加到自己的收藏,POST到后台、给收藏的表添加记录
~
~
~
是用图形化界面 把整个版面 用鼠标拖出来。
然后逐一添加事件吗?
有个File类 专门建文档和文件夹的,能实现收藏和整理的功能。
直接获得地址 然后在某盘创个拥有当前页面标题的HTML文件。
算不算是实现了呢 ?
有灵感了吗?
建议多查API,很有用
当然如果说要实现的话 只有把握实现百分之七十 八十左右。
有些技术层面上的东西无法实现的。 楼上说HTTP协议
有这个必要吗??
1、创建表结构
2、点击JavaScript方法触发写入数据库
3、收藏界面进行数据库查询展示