0

I am migrating Lucene from version 2 to 7.7.1 and facing below issue while upgrading lucene search. Getting NoClassDefFoundError for CommonTermsQuery even though the jar which it is part of is included(lucene-queries-7.7.1.jar). Can you please suggest what is missing here.

Error Log:

_Apr 12, 2019 5:07:29 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path threw 
exception [javax.servlet.ServletException: java.lang.NoClassDefFoundError:  
       org/apache/lucene/queries/CommonTermsQuery] with root cause
java.lang.NoClassDefFoundError: org/apache/lucene/queries/CommonTermsQuery
at     org.apache.lucene.search.highlight.WeightedSpanTermExtractor.extract(WeightedSpanTermExtractor.java:149)
at org.apache.lucene.search.highlight.WeightedSpanTermExtractor.extract(WeightedSpanTermExtractor.java:112)
at org.apache.lucene.search.highlight.WeightedSpanTermExtractor.getWeightedSpanTerms(WeightedSpanTermExtractor.java:513)
at org.apache.lucene.search.highlight.QueryScorer.initExtractor(QueryScorer.java:218)
at org.apache.lucene.search.highlight.QueryScorer.init(QueryScorer.java:186)
at org.apache.lucene.search.highlight.Highlighter.getBestTextFragments(Highlighter.java:201)
at org.apache.lucene.search.highlight.Highlighter.getBestFragments(Highlighter.java:161)
at org.apache.lucene.search.highlight.Highlighter.getBestFragments(Highlighter.java:465)_

Code Snippet:

...
TokenStream tokenStream = analyzer.tokenStream(searchField.toLowerCase(), new 
StringReader(content));
        preview = highlighter.getBestFragments(tokenStream, content, 3, "...");
...

2 Answers2

0

You need to add lucene-queries-7.7.1.jar to your classpath. (BTW - newer version already exists - 8.0.0)

Gal Naor
  • 2,397
  • 14
  • 17
  • Thanks, @galando for your response. As mentioned, I have added lucene-queries-7.7.1.jar in the classpath. It is visible in the classpath, referenced libraries. I am still getting this error. I tried with the latest version but they have removed customQuery class in this version so I had to revert to it's previous version. – Kiran Kumar Apr 14 '19 at 17:27
0

Eclipse was referring to an older jar. I did below things to resolve my issue. If you have added the jar in the build path and if it is visible in the referenced library then.

  • Check whether jar is present in eclipse cache: Workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/project/WEB-INF/lib

  • Then go to Right click the project > Properties > Deployment Assembly: Check for your jar, if it is missing then add it.

Clean build the project. It works fine.