Java 创建新的lucene索引未找到类错误
我正在使用lucene 4.0,我想通过以下方式创建一个新的Java 创建新的lucene索引未找到类错误,java,lucene,noclassdeffounderror,Java,Lucene,Noclassdeffounderror,我正在使用lucene 4.0,我想通过以下方式创建一个新的indexWriter: IndexWriter index = LuceneUtils.createIndexWriter(indexPath, true); (它使用lucene 3.6工作) 其中indepath是一个带有索引路径的字符串。我得到了这个错误: Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/lucene/analysis/
indexWriter
:
IndexWriter index = LuceneUtils.createIndexWriter(indexPath, true);
(它使用lucene 3.6工作)
其中indepath
是一个带有索引路径的字符串。我得到了这个错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/lucene/analysis/SimpleAnalyzer
at lucene.IndexCreator.<init>(IndexCreator.java:25)
at main.Main.main(Main.java:72)
Caused by: java.lang.ClassNotFoundException: org.apache.lucene.analysis.SimpleAnalyzer
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)
... 2 more
线程“main”java.lang.NoClassDefFoundError中的异常:org/apache/lucene/analysis/SimpleAnalyzer
位于lucene.IndexCreator(IndexCreator.java:25)
在main.main.main(main.java:72)
原因:java.lang.ClassNotFoundException:org.apache.lucene.analysis.SimpleAnalyzer
位于java.net.URLClassLoader$1.run(URLClassLoader.java:202)
位于java.security.AccessController.doPrivileged(本机方法)
位于java.net.URLClassLoader.findClass(URLClassLoader.java:190)
位于java.lang.ClassLoader.loadClass(ClassLoader.java:306)
位于sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
位于java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 还有两个
我已经读到,除了lucene-core-4.0.0.jar
,我还需要向项目中添加lucene-analyzers-common-4.0.0.jar
,但我得到了相同的错误。
事实上,
lucene-analyzers-common-4.0.0.jar内部的SimpleAnalyzer.class
的路径不是org.apache.lucene.analysis.SimpleAnalyzer
,而是org.apache.lucene.analysis.core.SimpleAnalyzer
,看起来您的类路径中可能有一个3.6jar。您能否验证旧版本是否没有被引入,可能是由于可传递依赖关系吗?您的项目中有一个旧版本的lucene core jar
。在以前的版本中,SimpleAnalyzer类的路径是org.apache.lucene.analysis.SimpleAnalyzer
。
在编译期间,系统能够在该路径上找到SimpleAnalyzer
。但在运行时,它指的是新版本。现在该类存在于lucene-analyzers-common-4.0.0.jar
的不同路径下。因此,NoClassDefFoundError
您可以通过阅读以下内容来进一步理解它-mvn依赖关系:如果使用Maven,树将完成此工作。如果使用gradle,则树将完成此工作。