I am getting NoClassDefFoundError even when CommonTermsQuery is included in the jar and i can see it in the build path. What could be the issue?

551 views Asked by At

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

There are 2 answers

1
Gal Naor On

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

0
Kiran Kumar On

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.