Class not found exception for org.apache.lucene.util.Version

I am using Elasticsearch6.4 Java High Level REST Client.
I am using lucene-core-7.4.0.jar and lucene-queryparser-7.4.0.jar,
but im getting the following exception.

24-Oct-2018 11:43:31.164 SEVERE [http-nio-8080-exec-9] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [javax.ws.rs.core.Application] in context with path [/ws_Sanjay] threw exception [org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: org/apache/lucene/util/Version] with root cause
java.lang.ClassNotFoundException: org.apache.lucene.util.Version
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1333)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1167)
at org.elasticsearch.Version.(Version.java:47)
at org.elasticsearch.common.logging.DeprecationLogger.(DeprecationLogger.java:158)
at org.elasticsearch.action.search.SearchRequest.(SearchRequest.java:61)
at com.em.core.services.impl.SearchService.search(SearchService.java:94)
at com.em.core.services.SearchService.search(SearchService.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:76)
at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:277)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:272)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:268)
at org.glassfish.jersey.internal.Errors.process(Errors.java:316)
at org.glassfish.jersey.internal.Errors.process(Errors.java:298)
at org.glassfish.jersey.internal.Errors.process(Errors.java:268)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:289)
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:256)
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:703)
at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:416)
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:370)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:389)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:342)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:229)

org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

When i searched for that exception, i came across a solution that lucene-core-xxx.jar would be missing along with some dependency jars. I already have lucene-core-7.4.0.jar.

asm-6.2.1.jar
aws-java-sdk-1.11.138.jar
BASE64Decoder.jar
batik-all-1.7.jar
cdi-api.jar
cglib-nodep-2.2.3.jar
commons-beanutils-1.8.3.jar
commons-httpclient-3.1.jar
commons-lang-2.4.jar
commons-math3-3.5.jar
commons-net-3.3.jar
commons-pool2-2.4.2.jar
concurrent-trees-2.4.0.jar
diffutils-1.3.0.jar
dom4j-1.6.1.jar
dropbox-core-sdk-3.0.3.jar
eclipselink-2.7.3.jar
ehcache-2.8.1.jar
elasticsearch-6.4.0.jar
elasticsearch-core-6.4.0.jar
elasticsearch-rest-client-6.4.0.jar
elasticsearch-rest-high-level-client-6.4.0.jar
elasticsearch-x-content-6.4.0.jar
evo-inflector-1.0.1.jar
ews-java-api-2.0.jar
geocode.jar
google-api-client-1.22.0.jar
google-api-client-servlet-1.22.0.jar
google-api-services-drive-v2-rev268-1.22.0.jar
google-api-services-drive-v3-rev71-1.22.0.jar
google-http-client-1.22.0.jar
google-http-client-jackson-1.22.0.jar
google-http-client-jackson2-1.22.0.jar
google-oauth-client-1.22.0.jar
google-oauth-client-java6-1.22.0.jar
google-oauth-client-jetty-1.22.0.jar
grammatica-1.5.jar
gson-2.2.4.jar
guava-14.0.1.jar
hibernate-c3p0-4.3.4.Final.jar
hk2-api-2.5.0-b62.jar
hk2-locator-2.5.0-b62.jar
hk2-utils-2.5.0-b62.jar
hppc-0.8.1.jar
httpasyncclient-4.1.4.jar
httpclient-4.5.3.jar
httpcore-4.4.6.jar
httpcore-nio-4.4.10.jar
itextpdf-5.5.6.jar
jackson-annotations-2.9.7.jar
jackson-core-2.9.7.jar
jackson-databind-2.9.7.jar
javax.inject-2.5.0-b42.jar
javax.websocket-api-1.0-rc4.jar
javax.websocket-api-1.1.jar
jaxrs-ri-2.27.jar
jboss-logging-3.3.2.Final.jar
jcommon-1.0.0.jar
jedis-2.8.0.jar
jersey-common-2.27.jar
jersey-container-servlet-core-2.27.jar
jersey-guava-2.26-b03.jar
jersey-hk2-2.27.jar
jersey-server-2.27.jar
jfreechart-1.0.1.jar
joda-time-2.8.jar
json-org.jar
json_simple-1.1.jar
jsoup-1.8.3.jar
jxl-2.6.12.jar
lang-mustache-client-6.4.0.jar
log4j-api-2.11.0.jar
log4j-core-2.11.0.jar
mibble-mibs-2.9.3.jar
mibble-parser-2.9.3.jar
mongo-2.10.1.jar
mpxj.jar
mybatis-3.4.6.jar
mysql-connector-java-8.0.12.jar
opencsv-2.3.jar
org.eclipse.persistence.core-2.7.3.jar
org.mortbay.jetty.server_6.1.22.jar
org.mortbay.jetty.util_6.1.22.jar
poi-3.10-beta2.jar
poi-ooxml-3.9.jar
poi-ooxml-schemas-3.7.jar
quartz-2.2.1.jar
rank-eval-client-6.4.0.jar
Rhino_1_7R4.jar
rztbase.jar
rztbuild.jar
shiro-core-1.2.3.jar
shiro-ehcache-1.2.3.jar
slf4j-api-1.7.6.jar
snmp6_0.jar
sonar-ant-task-1.3.jar
sqlite-jdbc-3.7.2.jar
thumbnailator-0.4.8.jar
validation-api-2.0.1.Final.jar
velocity-1.7.jar
xml-apis-ext-1.3.04.jar
xmlbeans-2.3.0.jar
xmlsec-1.3.0.jar
zip4j_1.3.2.jar

these are the other jars im using for my project.
Is there any dependency jar need to be added or any other solution will be there?
and also im getting
24-Oct-2018 13:10:01.768 SEVERE [http-nio-8080-exec-9] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [javax.ws.rs.core.Application] in context with path [/ws_Sanjay] threw exception [org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: Could not initialize class org.elasticsearch.action.search.SearchRequest] with root cause
java.lang.NoClassDefFoundError: Could not initialize class org.elasticsearch.action.search.SearchRequest
at com.em.core.services.impl.SearchService.search(SearchService.java:94)
at com.em.core.services.SearchService.search(SearchService.java:48)

Could you try with Elasticsearch 6.4.2 instead to see if it changes anything?

Should i upgrade any other jars with that?

I tried wit elasticsearch 6.4.2. jar but still im getting the exception on searchservice.

24-Oct-2018 15:46:23.651 SEVERE [http-nio-8080-exec-7] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [javax.ws.rs.core.Application] in context with path [/ws_Sanjay] threw exception [org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: org/apache/lucene/util/Version] with root cause
java.lang.ClassNotFoundException: org.apache.lucene.util.Version
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1333)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1167)
at org.elasticsearch.Version.(Version.java:47)
at org.elasticsearch.common.logging.DeprecationLogger.(DeprecationLogger.java:158)
at org.elasticsearch.action.search.SearchRequest.(SearchRequest.java:61)
at com.em.core.services.impl.SearchService.search(SearchService.java:94)
at com.em.core.services.SearchService.search(SearchService.java:48)

my search code is as follows
public Response search(ServiceExecutionContext ctx,SearchInput input) throws ExecException {
Response response = new Response();
try {
CommonService.getSessionAttribute(ctx);
RestHighLevelClient client = IndexUtils.getIndexClient();
if (client == null) {
response.setResponse("Internal Server Error,did not get client");
return response;
}
String returnFields = "State,Stage,Assignee,Requester,Title,Risk,Priority,Reporter,Module,Id,Planned Start,Planned End,Topic,Blueprint,IP Address";

		String finalFieldSetForSearch = "Blueprint,IP Address,Article,Article Attachment"+(input.getField() != null && !input.getField().trim().equals("") ? ","+input.getField() : "");
		String[] fieldSet = finalFieldSetForSearch.split(",");
		
		MultiSearchRequest request = new MultiSearchRequest();
		for(int i=0;i<IndexConstants.moduleArray.length;i++){
			String indexName = IndexUtils.getIndexName();
			indexName += "_"+IndexConstants.moduleArray[i].toLowerCase();
			SearchRequest searchRequest = new SearchRequest(indexName);
			SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
		    searchRequest.source(searchSourceBuilder);
			String[] excludes = null;
			searchSourceBuilder.fetchSource(returnFields.split(","),excludes );
			MultiMatchQueryBuilder queryBuilder = QueryBuilders.multiMatchQuery(input.getTerm().toLowerCase(), fieldSet);
			searchSourceBuilder.query(QueryBuilders.boolQuery().must(queryBuilder).must(QueryBuilders.termQuery("Archive","false")));
			searchRequest.source(searchSourceBuilder);
			request.add(searchRequest);
		}
		MultiSearchResponse searchResponse = null;
		JSONArray jsonArray = new JSONArray();
		try {
			searchResponse = client.multiSearch(request);
			 for (int i = 0; i < searchResponse.getResponses().length; i++) {
			        SearchHit[] hits = searchResponse.getResponses()[i].getResponse().getHits().getHits();
			        for (SearchHit hit : hits) {
			        	jsonArray.add(hit.getSourceAsMap());
			        }
			    }
		} catch (IOException e) {
			e.printStackTrace();
		}
		try {
			client.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		response.setResponse(new Gson().toJson(jsonArray));
	} catch (SearchPhaseExecutionException e) {
		e.printStackTrace();
		logger.logError(CLASSNAME,"Error Code : " + EMErrorCodes.EMERR002084 + " has been occured in the process");
		logger.logDebug(CLASSNAME,"Error Message : " + EMErrorCodes.getErrorMessage(EMErrorCodes.EMERR002084));
		throw new ExecException(ErrorCodes.BAD_REQUEST,null,"Node not available");
	}  catch (NoNodeAvailableException e) {
		logger.logError(CLASSNAME,"Error Code : " + EMErrorCodes.EMERR002086 + " has been occured in the process");
		logger.logDebug(CLASSNAME,"Error Message : " + EMErrorCodes.getErrorMessage(EMErrorCodes.EMERR002086));
		
		throw new ExecException(ErrorCodes.BAD_REQUEST,null,"Node not available");
	} catch (ElasticsearchException e) {
		e.printStackTrace();
		logger.logError(CLASSNAME,"error :"+e.getMessage());
		logger.logDebug(CLASSNAME,"error :"+e.getMessage());
	}
	return response;
}

Are you using maven ?

No, im not using maven

So you are probably missing some dependencies, or you are providing the wrong ones.

Would be much easier to use a dependency manager like Maven or Gradle.

My pom.xml is

In the dependency hierarchy its showing many jars. Those are the jars which i need to add or elasticsearch-6.4.0 contains those dependencies?

You need to depend on the High Level Rest client and not elasticsearch itself. Elasticsearch will come as a transitive dependency.

Then you need to add all the jars to your classpath. And make sure it does not conflict with any other jar from your own project.

i have a question.

the jars shown below elasticsearch-rest-high-level-client are the jars needed to be added or the rest high level client jar already contains it?

You need to add all the jars mentioned here.

thank you it was very helpful.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.