Eclipse or tomcat: got an error by trying to create a client

Hello everyone,

I would like to access to my elasticsearch throught eclipse. So, I followed the tutorial https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/index.html .
Therefore, I create a class java in my eclipse project:

import java.net.InetAddress;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
public class client {

//initialization
private String serverIpAddr = "localhost";
// on startup
Client client = TransportClient.builder().build()
        .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(serverIpAddr), 9300));
// on shutdown
//client.close();

}

I imported the following jar: elasticsearch-2.3.3.jar, joda-time-2.8.jar, lucene-core-5.4.1.jar and guava-19.0.jar. i also included in the root of my eclipse project the file pom.xml (as indicated in the elasticsearch website).

However, i got an error about InetAddress.getByName(serverIpAddr) but there is no suggestion.

Do you have an idea about this problem ? Futhermore, do you have a tutorial more detailed ?

Thank you for your attention and your help.

S

What kind of "error" do you have?

Thank you very much for your reply. I got the right answer (it was a stupid error in my side :stuck_out_tongue: )

Here is the correction:
public class client {

//initialization
private static String serverIpAddr = "localhost";
// on startup
public static void main(String[] arg) throws UnknownHostException{
Client client = TransportClient.builder().build()
        .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(serverIpAddr), 9300));


// on shutdown
client.close();
}

}