Error while using the Java API

I started a new Java project. I'm using the elasticsearch-2.0.0.jar file, included it in my project, and the guava-18.0.jar file. I did not do any other configurations.

I'm using Elasticsearch 2.0.0 and it is running on localhost port 9200. The following is my Java code, all I'm trying to do is create a client:

  public void createClient(String Username) throws UnknownHostException {
           Client client = TransportClient.builder().build()
                          .addTransportAddress(new InetSocketTransportAddress(InetAddress.getLocalHost(), 9200))
                          .addTransportAddress(new InetSocketTransportAddress(InetAddress.getLocalHost(), 9200));

}

However, it is giving me the following error:

 Nov 26, 2015 2:39:42 PM org.elasticsearch.plugins.PluginsService <init>
 INFO: [Hydro] loaded [], sites []
 Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/lucene/util/Version
     at org.elasticsearch.Version.<clinit>(Version.java:44)
     at org.elasticsearch.client.transport.TransportClient$Builder.build(TransportClient.java:117)
     ......
 Caused by: java.lang.ClassNotFoundException: org.apache.lucene.util.Version
     at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
     at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
     at java.security.AccessController.doPrivileged(Native Method)
     at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
     ... 4 more
 Java Result: 1

I prefer using a Java project and not a Maven project because I dont have any experience with Maven. Please let me know which jar files that I need??

@Israaaaa here is what mvn dependency:tree gives on the 2.0.0 project (I removed test scoped libs):

[INFO] org.elasticsearch:elasticsearch:jar:2.0.0
[INFO] +- org.apache.lucene:lucene-core:jar:5.2.1:compile
[INFO] +- org.apache.lucene:lucene-backward-codecs:jar:5.2.1:compile
[INFO] +- org.apache.lucene:lucene-analyzers-common:jar:5.2.1:compile
[INFO] +- org.apache.lucene:lucene-queries:jar:5.2.1:compile
[INFO] +- org.apache.lucene:lucene-memory:jar:5.2.1:compile
[INFO] +- org.apache.lucene:lucene-highlighter:jar:5.2.1:compile
[INFO] +- org.apache.lucene:lucene-queryparser:jar:5.2.1:compile
[INFO] |  \- org.apache.lucene:lucene-sandbox:jar:5.2.1:compile
[INFO] +- org.apache.lucene:lucene-suggest:jar:5.2.1:compile
[INFO] |  \- org.apache.lucene:lucene-misc:jar:5.2.1:compile
[INFO] +- org.apache.lucene:lucene-join:jar:5.2.1:compile
[INFO] |  \- org.apache.lucene:lucene-grouping:jar:5.2.1:compile
[INFO] +- org.apache.lucene:lucene-spatial:jar:5.2.1:compile
[INFO] +- org.apache.lucene:lucene-expressions:jar:5.2.1:compile
[INFO] |  +- org.antlr:antlr-runtime:jar:3.5:compile
[INFO] |  +- org.ow2.asm:asm:jar:4.1:compile
[INFO] |  \- org.ow2.asm:asm-commons:jar:4.1:compile
[INFO] +- com.spatial4j:spatial4j:jar:0.4.1:compile
[INFO] +- com.vividsolutions:jts:jar:1.13:compile
[INFO] +- com.github.spullara.mustache.java:compiler:jar:0.8.13:compile
[INFO] +- com.google.guava:guava:jar:18.0:compile
[INFO] +- com.carrotsearch:hppc:jar:0.7.1:compile
[INFO] +- joda-time:joda-time:jar:2.8.2:compile
[INFO] +- org.joda:joda-convert:jar:1.2:compile
[INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.5.3:compile
[INFO] +- com.fasterxml.jackson.dataformat:jackson-dataformat-smile:jar:2.5.3:compile
[INFO] +- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.5.3:compile
[INFO] |  \- org.yaml:snakeyaml:jar:1.12:compile
[INFO] +- com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:jar:2.5.3:compile
[INFO] +- io.netty:netty:jar:3.10.5.Final:compile
[INFO] +- com.ning:compress-lzf:jar:1.0.2:compile
[INFO] +- com.tdunning:t-digest:jar:3.0:compile
[INFO] +- org.hdrhistogram:HdrHistogram:jar:2.1.6:compile
[INFO] +- commons-cli:commons-cli:jar:1.3.1:compile
[INFO] +- org.codehaus.groovy:groovy-all:jar:indy:2.4.4:compile
[INFO] +- log4j:log4j:jar:1.2.17:compile
[INFO] +- log4j:apache-log4j-extras:jar:1.2.17:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.6.2:compile
[INFO] +- net.java.dev.jna:jna:jar:4.1.0:compile
[INFO] \- com.twitter:jsr166e:jar:1.1.0:compile

Good luck for adding that manually!

1 Like

LOL Done! THANK YOU!