在导入lucene-core-4.4.0.jar包源码的时候遇到了这么一个异常:
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.apache.lucene.index.LiveIndexWriterConfig.<init>(LiveIndexWriterConfig.java:122)
at org.apache.lucene.index.IndexWriterConfig.<init>(IndexWriterConfig.java:148)
at com.MemoryTest.<clinit>(MemoryTest.java:32)
Caused by: java.lang.IllegalArgumentException: A SPI class of type org.apache.lucene.codecs.Codec with name 'Lucene42' does not exist. You need to add the corresponding JAR file supporting this SPI to your classpath.The current classpath supports the following
names: []
at org.apache.lucene.util.NamedSPILoader.lookup(NamedSPILoader.java:109)
at org.apache.lucene.codecs.Codec.forName(Codec.java:95)
at org.apache.lucene.codecs.Codec.<clinit>(Codec.java:122)
... 3 more
找到出错的这个类org.apache.lucene.util.SPIClassIterator:
public final class SPIClassIterator<S> implements Iterator<Class<? extends S>> {
private static final String META_INF_SERVICES = "META-INF/services/";
private final Class<S> clazz;
...
发现问题出在缺少META-INF/services这样的文件夹,然后找到jar包看到jar包中有这样的services文件夹,下面带了几个文件:
把jar包中的META-INF复制到src目录即可。
OK,成功,可以调试和研究lucene的源码咯。