ElasticSearch 2.0 Java API: java.lang.ClassNotFoundException: org.elasticsearch.common.settings.ImmutableSettings$Builder - elasticsearch

I have updated my Spring Boot project to use the new ElasticSearch 2 API and I get this error at startup:
Caused by: java.lang.NoClassDefFoundError: org/elasticsearch/common/settings/ImmutableSettings$Builder
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethods(Class.java:1975)
My relevant Maven dependencies are:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
<version>1.3.0.M5</version>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>2.0.0-rc1</version>
</dependency>
Do you have any hint on what I am doing wrong?
Thanks

In ES 2.0, the ImmutableSettings class was indeed removed. This issue mentions it and the breaking changes documentation for 2.0 also mention it.
Instead you can now use Settings.builder() instead of ImmutableSettings.builder(). The current implementation of the Settings class can be seen here
All the questions that still use ImmutableSettings are questions about pre-2.0 versions of Elasticsearch.

Related

Does ScyllaDB Support Latest Version of Metrics?

When I launch ScyllaDB for the first time:
Cluster cluster = Cluster.builder().addContactPoints("xx.xxx.xx.xxx").build();
Session session = cluster.connect("my_scylladb_cluster");
System.out.println(session.isClosed());
I get the following error:
===== Using optimized driver!!! =====
Exception in thread "main" java.lang.NoClassDefFoundError: com/codahale/metrics/JmxReporter
at com.datastax.driver.core.Metrics.<init>(Metrics.java:156)
at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1773)
at com.datastax.driver.core.Cluster.init(Cluster.java:228)
at com.datastax.driver.core.Cluster.connectAsync(Cluster.java:401)
at com.datastax.driver.core.Cluster.connect(Cluster.java:352)
at scylladbX.ScyllaDBXMain.main(ScyllaDBMain.java:12)
Caused by: java.lang.ClassNotFoundException: com.codahale.metrics.JmxReporter
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 6 more
In my Maven POM file I'm using the latest version of Metrics:
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
<version>4.2.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.dropwizard.metrics/metrics-graphite -->
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-graphite</artifactId>
<version>4.2.9</version>
</dependency>
I noticed that if I downgrade to a much earlier version of Metrics, the problem goes away:
<!-- https://mvnrepository.com/artifact/com.codahale.metrics/metrics-core -->
<dependency>
<groupId>com.codahale.metrics</groupId>
<artifactId>metrics-core</artifactId>
<version>3.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.codahale.metrics/metrics-graphite -->
<dependency>
<groupId>com.codahale.metrics</groupId>
<artifactId>metrics-graphite</artifactId>
<version>3.0.0</version>
</dependency>
Does ScyllaDB not support the latest version of Metrics? What is the latest version supported?
Thanks
The DataStax Java Driver documentation here has a section about the problem you saw:
While the driver depends on Metrics 3.2.x, it also works with Metrics 4, with some caveats.
In Metrics 4, JMX reporting was moved to a separate module, metrics-jmx. Because of this you are likely to encounter the following exception at runtime when initializing a Cluster:
Exception in thread "main" java.lang.NoClassDefFoundError: com/codahale/metrics/JmxReporter
at com.datastax.driver.core.Metrics.<init>(Metrics.java:103)
at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1402)
at com.datastax.driver.core.Cluster.init(Cluster.java:159)
at com.datastax.driver.core.Cluster.connectAsync(Cluster.java:330)
at com.datastax.driver.core.Cluster.connectAsync(Cluster.java:305)
at com.datastax.durationtest.core.DurationTest.createSessions(DurationTest.java:360)
....
Caused by: java.lang.ClassNotFoundException: com.codahale.metrics.JmxReporter
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
... 8 more
That document also has suggestions what to do in this case.
In any case, this problem has nothing to do with Scylla (the backend server you want to connect to) - and is just a problem with the Java client ("driver") you are using.

YARN SLS - java.lang.NoClassDefFoundError: javax/activation/DataSource [duplicate]

i'm trying to generate class stubs for a wsdl with Intellij-Idea 2017.2.5 (Webservices -> Generate code from wsdl...) using JDK-9
I'm getting this exception and i wonder how to tell intellij to pass "--add-modules java.activation" to complete the operation.
(i guess i should run wsimport from the command line...)
Exception in thread "main" java.lang.NoClassDefFoundError: javax/activation/DataSource
at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl.<clinit>(RuntimeBuiltinLeafInfoImpl.java:461)
at com.sun.xml.bind.v2.model.impl.RuntimeTypeInfoSetImpl.<init>(RuntimeTypeInfoSetImpl.java:65)
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.createTypeInfoSet(RuntimeModelBuilder.java:133)
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.createTypeInfoSet(RuntimeModelBuilder.java:85)
at com.sun.xml.bind.v2.model.impl.ModelBuilder.<init>(ModelBuilder.java:156)
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.<init>(RuntimeModelBuilder.java:93)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:455)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:303)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:142)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1174)
at com.sun.tools.xjc.reader.xmlschema.bindinfo.BindInfo.getJAXBContext(BindInfo.java:335)
at com.sun.tools.xjc.reader.internalizer.SCDBasedBindingSet.apply(SCDBasedBindingSet.java:235)
at com.sun.tools.xjc.ModelLoader.createXSOM(ModelLoader.java:541)
at com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.bind(SchemaCompilerImpl.java:269)
at com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.bind(SchemaCompilerImpl.java:95)
at com.sun.tools.ws.processor.modeler.wsdl.JAXBModelBuilder.bind(JAXBModelBuilder.java:142)
at com.sun.tools.ws.processor.modeler.wsdl.WSDLModeler.buildJAXBModel(WSDLModeler.java:2244)
at com.sun.tools.ws.processor.modeler.wsdl.WSDLModeler.internalBuildModel(WSDLModeler.java:191)
at com.sun.tools.ws.processor.modeler.wsdl.WSDLModeler.buildModel(WSDLModeler.java:137)
at com.sun.tools.ws.wscompile.WsimportTool.buildWsdlModel(WsimportTool.java:391)
at com.sun.tools.ws.wscompile.WsimportTool.run(WsimportTool.java:204)
at com.sun.tools.ws.wscompile.WsimportTool.run(WsimportTool.java:179)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at com.sun.tools.ws.Invoker.invoke(Invoker.java:135)
at com.sun.tools.ws.WsImport.main(WsImport.java:57)
Caused by: java.lang.ClassNotFoundException: javax.activation.DataSource
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
... 28 more
Based on your error message, you need to add the following dependency in your pom.xml
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
From SDK 9, for JAXB to work for web services you need to also have the following dependencies if you do not already have them as they are not part of the SDK.
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.0</version>
</dependency>
I guess it can be useful. I have these additional packages in my soap project when switch from Java 8 to 10. Gradle:
compile "javax.xml.bind:jaxb-api:2.3.0"
compile "javax.activation:activation:1.1"
compile "com.sun.xml.bind:jaxb-impl:2.3.0"
compile "com.sun.xml.bind:jaxb-core:2.3.0"
compile "com.sun.xml.ws:rt:2.3.0"
compile "com.sun.xml.ws:jaxws-rt:2.3.0"
Just for other people with the same exception coming here:
This problem can also occur if you use a web server such as tomcat and if you need the activation jar to be present there as well. One possible solution is to put it in the lib folder of tomcat (or to use the common.loader functionality).
I had the same problem. After changing the project jdk, it works for me.
Change project jdk to 8.

Spring elastic-search integration: Caused by: java.lang.NoSuchMethodError: org.elasticsearch.common.settings.Settings$Builder.put([Ljava/lang/Object;)

I am upgrading elastic 2.x to 6.x. I have to update the spring data dependency as well to do the elastic upgrade. (Using elastic cloud managed service with x-pack-transport)
Here is my dependencies:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>x-pack-transport</artifactId>
<version>5.6.1</version>
</dependency>
This include elasticsearch dependency version 6.2.2.
I am getting following error while initialize the spring application.
Connection Code:
private Client getEsClient(String clusterIps, String clusterName) throws UnknownHostException
{
Settings settings = Settings.builder()
.put("client.transport.nodes_sampler_interval", "5s")
.put("client.transport.sniff", false)
.put("transport.tcp.compress", true)
.put("cluster.name", "cluster-id")
.put("xpack.security.transport.ssl.enabled", true)
.put("request.headers.X-Found-Cluster", "cluster-id")
.put("xpack.security.user", "user:password")
.put("xpack.security.transport.ssl.verification_mode", "none")
.build();
TransportClient client = new PreBuiltXPackTransportClient(settings);
client.addTransportAddress(
new TransportAddress(InetAddress.getByName("<cluster>.us-west1.gcp.cloud.es.io"), 9343));
return client;
}
Here is the exception thrown while initializing the spring context:
Caused by: java.lang.NoSuchMethodError: org.elasticsearch.common.settings.Settings$Builder.put([Ljava/lang/Object;)Lorg/elasticsearch/common/settings/Settings$Builder;
at org.elasticsearch.xpack.notification.email.Account.(Account.java:71)
at org.elasticsearch.xpack.XPackPlugin.(XPackPlugin.java:192)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.elasticsearch.plugins.PluginsService.loadPlugin(PluginsService.java:556)
Please let me know if anyone encounter this problem before.
Thanks for your help in advance :)
I figured out the issue, I was using incompatible version of x-pack dependency which is 5.6.1, spring data 3.1.3.RELEASE uses 6.2.2 version of elastic driver so we should use compatible x-pack dependency and that is 6.2.2.
Here is the updated dependency
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>x-pack-transport</artifactId>
<version>6.2.2</version>
</dependency>
Documentation available here: https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-xpack-client.html

ClassNotFoundException: DirectoryService with apacheds-all already included

I am implemented LDAP authentication in my Spring Boot Application. The dependencies added are as follows:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-ldap</artifactId>
</dependency>
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-all</artifactId>
</dependency>
However I am still getting following ClassNotFoundException:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain'
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]
Caused by: java.lang.NoClassDefFoundError: org/apache/directory/server/core/DirectoryService
Caused by: java.lang.ClassNotFoundException: org.apache.directory.server.core.DirectoryService
My maven dependency tree clearly shows apacheds-all is added successfully.
Why am I still getting this error?
Spring Security doesn't support Apache DS 2.0. Instead, you need to use 1.5.5. Also, note that later 1.5.x versions are not supported due to breaking API changes.

How do I integrate EhCache 2.9 & JGroups replication?

http://ehcache.org/generated/2.9.0/html/ehc-all/#page/Ehcache_Documentation_Set%2Fco-use_supported_types.html%23wwconnect_header
This documentation from ehcache 2.9 says it will support RMI, JGroups, and JMS. But, clearly, the APIs in ehcache-2.9 JAR have changed and the docs are not up-to-date. After I got the error below, a closer look at its EhCache ClassLoaderUtils confirms this method (getStandardClassLoader()) indeed, does not exist.
I'm looking for bright ideas on how to work around this issue, so I can use JGroups replication in ehcache 2.9.
I am using the latest ehcache-jgroupsreplication maven dependency:
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-jgroupsreplication</artifactId>
<version>1.7</version>
</dependency>
Caused by: net.sf.ehcache.CacheException: java.lang.NoSuchMethodError: net.sf.ehcache.util.ClassLoaderUtil.getStandardClassLoader()Ljava/lang/ClassLoader;
at net.sf.ehcache.CacheManager.init(CacheManager.java:426)
at net.sf.ehcache.CacheManager.<init>(CacheManager.java:270)
at org.springframework.cache.ehcache.EhCacheManagerFactoryBean.afterPropertiesSet(EhCacheManagerFactoryBean.java:157)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1625)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1562)
... 39 more
Caused by: java.lang.NoSuchMethodError: net.sf.ehcache.util.ClassLoaderUtil.getStandardClassLoader()Ljava/lang/ClassLoader;
at net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory.createCachePeerProvider(JGroupsCacheManagerPeerProviderFactory.java:61)
at net.sf.ehcache.config.ConfigurationHelper.createCachePeerProviders(ConfigurationHelper.java:136)
at net.sf.ehcache.CacheManager.configure(CacheManager.java:795)
at net.sf.ehcache.CacheManager.doInit(CacheManager.java:471)
at net.sf.ehcache.CacheManager.init(CacheManager.java:395)
... 43 more
I figured it out and post answer for others to benefit.
I had to create my own custom "JGroupsCacheManagerPeerProviderFactory" instead of using the one in the ehcache-jgroupsreplication 1.7 maven dependency.
Really, the only change to it was to use a different classload and NOT call the API that no longer exists in ehcache-2.9.jar :
//final ClassLoader contextClassLoader = ClassLoaderUtil.getStandardClassLoader();
// CHANGE: Use Thread's contextClassLoader instead of invalid API
final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
Then, in ehcache.xml, I registered my custom one like this, instead of registering the factory in the ehcache-jgroupsreplication JAR:
<cacheManagerPeerProviderFactory
class="my.custom.JGroupsCacheManagerPeerProviderFactory"
properties="file=jgroups/jgroups-unified-udp.xml"/>

Resources