Could Not Initialize Class PreBuiltTransportClient

So I am working on a Java Spring project that IS NOT USING MAVEN and I am having some trouble getting my TransportClient started. I am using elasticsearch 5.1.1. My Code:

import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.elasticsearch.transport.client.*;
import java.net.InetSocketAddress;

@Controller
public class DBTest{
	@RequestMapping(value="/elastictest",method=RequestMethod.GET)
	public void elasticTestFunction(ModelMap modelMap){
		try{
			TransportClient client = new PreBuiltTransportClient(Settings.EMPTY);
			client.addTransportAddress(new InetSocketTransportAddress( new InetSocketAddress("127.0.0.1", 9200) ) );
			client.close();
		}catch (Exception e){
			e.printStackTrace();	
		}
	}
}

When attempting to create my transport client I get an error: Could not initialize class org.elasticsearch.transport.client.PreBuiltTransportClient. Stacktrace below:

        java.lang.NoClassDefFoundError: Could not initialize class org.elasticsearch.transport.client.PreBuiltTransportClient
	com.inspirave.controller.DBTest.elasticTestFunction(DBTest.java:49)
	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	java.lang.reflect.Method.invoke(Unknown Source)
	org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
	org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
	org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
	org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:844)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
	com.thetransactioncompany.cors.CORSFilter.doFilter(CORSFilter.java:205)
	com.thetransactioncompany.cors.CORSFilter.doFilter(CORSFilter.java:266)

Has anyone encountered an error like this before? Thank you for your help.

You did not add needed dependencies to your project.

Okay, Is there somewhere where I can find a comprehensive list of all dependencies needed since I am not using maven?

Not any updated AFAIK.
On this forum you can probably find some of them.

Ideally, install maven, add just the transport client dependency, then run mvn dependency:tree and you will get that list.

HTH

Use a dependency management system to list you / download the files, with the techniques outlined here for example:

# 1. Download the latest ivy jar (currently it's v.2.4.0)
curl -L -O http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.4.0/ivy-2.4.0.jar

# 2. Run ivy.jar to retrieve all dependencies
java -jar ivy-2.4.0.jar -confs default -dependency org.elasticsearch.client transport 5.1.1 -retrieve "lib/[artifact]-[revision](-[classifier]).[ext]"
1 Like

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