Lucene导入源码运行异常A SPI class of type org.apache.lucene.codecs.Codec with name
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目录即可。
具体拷备到哪个META-INF文件路径下不确定, 一个是工程根目录下的(我的台机有效),另一个是eclipse-build/main下的(我的笔记本有效)

浙公网安备 33010602011771号