导致Lucene无法索引查询的NoClassDefFoundError
来源:互联网 发布:网络13邯大主教楼视频 编辑:程序博客网 时间:2024/05/20 02:55
Lucene乃是当今免费开源搜索引擎的霸主,确实它十分好用,发展势头也很生猛,在Apache组织的支持下不断的更新、推出新版本。
但是其存在一个隐藏的很深的bug,相信困扰了不少和我一样研究使用过它的人,这个bug从早期的版本到目前的V2.3.1一个存在,不能不说是一个遗憾。
具体触发这个bug的原因很复杂,在某些环境、服务器、应用中……
表现为建立索引文件和执行查询时报“NoClassDefFoundError”,跟进代码会发现是“SegmentReader”这个类型不能创建实例,但怎么看这个类都是存在的。其实问题在这(SegmentReader.java):
/** *//** The class which implements SegmentReader. */
private static Class IMPL;
static ...{
try ...{
String name =
System.getProperty("org.apache.lucene.SegmentReader.class",
SegmentReader.class.getName());
IMPL = Class.forName(name);
} catch (ClassNotFoundException e) ...{
throw new RuntimeException("cannot load SegmentReader class: " + e, e);
} catch (SecurityException se) ...{
try ...{
IMPL = Class.forName(SegmentReader.class.getName());
} catch (ClassNotFoundException e) ...{
throw new RuntimeException("cannot load default SegmentReader class: " + e, e);
}
}
}
private static Class IMPL;
static ...{
try ...{
String name =
System.getProperty("org.apache.lucene.SegmentReader.class",
SegmentReader.class.getName());
IMPL = Class.forName(name);
} catch (ClassNotFoundException e) ...{
throw new RuntimeException("cannot load SegmentReader class: " + e, e);
} catch (SecurityException se) ...{
try ...{
IMPL = Class.forName(SegmentReader.class.getName());
} catch (ClassNotFoundException e) ...{
throw new RuntimeException("cannot load default SegmentReader class: " + e, e);
}
}
}
看到这句没有“System.getProperty("org.apache.lucene.SegmentReader.class", SegmentReader.class.getName());”,鬼知道它什么时候把这个系统属性设入内存中的!它的本意是想动态加载SegmentReader,但反而有可能弄巧成拙,导致Class.forName报出NoClassDefFoundError,更要命的是在static{}代码段中的Error不会明确的显示在异常堆栈中,任你用什么debug手段都不能立即定位问题。
知道了问题,最简单的解决方法,很直接,改代码。把那个IMPL和static{}段干脆去掉,不利用系统属性动态加载就是了,就直接使用SegmentReader,就认准它了:-)
- 导致Lucene无法索引查询的NoClassDefFoundError
- lucene(索引的查询)
- Lucene对索引的查询
- lucene 基于索引的查询
- lucene索引的添加与查询
- lucene查询索引的6个步骤
- lucene 索引创建查询
- lucene 查询索引
- Lucene查询索引
- Lucene查询索引
- Lucene 查询索引库
- Lucene查询索引
- lucene索引数据库查询
- Lucene的入门例子 - 创建索引,利用索引查询
- MySQL前缀索引导致的慢查询
- lucene创建索引,分组查询
- lucene添加索引并查询
- lucene 创建索引 查询实例
- 在ORACLE中如何删除表中的重复数据的补充
- 击破struts 步步为营
- 到底去不去上海......
- 最佳PHP解析RSS类lastRSS
- 神州数码招聘软件测试工程师一道SQL笔试题
- 导致Lucene无法索引查询的NoClassDefFoundError
- Lotus Notes Traveler 测试成功 !上图~~~
- xp文件夹加密及文件加密应用详解
- 无废话C#设计模式之三:Abstract Factory
- .NET中的抽象工厂
- Struts的工作流程
- 《武林外传》之(零) 管理演绎
- xsl 应用实例
- 修改密码