java.lang.NoClassDefFoundError: org/elasticsearch/index/query/QueryBuilder

Hi Sir,

I am Kalyani Naidu, Working as an IT Professional in India.

I am facing a problem

java.lang.ClassNotFoundException: org.elasticsearch.index.query.QueryBuilder

--- It is happening when an trying to build a custom grant jar for mobile grant access in wso2.

I have received no problem in building the maven jar and also worked on sample it is also working fine.

But, When I am trying to restart wso2 its throwing the error message as below..

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoClassDefFoundError: org/elasticsearch/index/query/QueryBuilder
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration.getSupportedGrantTypes(OAuthServerConfiguration.java:614)
at org.wso2.carbon.identity.oauth.OAuthAdminService.getAllowedGrantTypes(OAuthAdminService.java:1091)
... 154 more
Caused by: java.lang.ClassNotFoundException: org.elasticsearch.index.query.QueryBuilder cannot be found by custom_grant_1.1.2_1.0.0
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:501)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 158 more
[2019-07-18 21:15:39,856] ERROR - ApplicationDispatcher Servlet.service() for servlet bridgeservlet threw exception
java.lang.NullPointerException
at org.apache.jsp.oauth.edit_jsp._jspService(edit_jsp.java:1076)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)

-- Elastic Java Client jar throwing this error when I load from wso2

the jar is placed is wso2/2.6.0/repository/components/lib - to support custom grant mobile support over cross cluster search!

  • I have a sample with elasticsearch java client its working absolutely fine. But its throwing error only when I tried using the maven generated jar in the wso2 libraries

please help.
am using elastic search 6.5.4
java 1.8
wso2 2.6.0

Welcome!

Could you please:

  • read this about how to format properly your code and why it's important
  • provide a pom.xml file which can help to reproduce your problem

Sure Sir,

my pom.xml

<groupId>org.wso2.is</groupId>
<modelVersion>4.0.0</modelVersion>
<artifactId>custom-grant</artifactId>
<version>1.1.2</version>
<packaging>jar</packaging>
<name>OAuth 2.0 Custom Grant</name>
<url>http://maven.apache.org</url>

 <properties>
    <elasticsearch.version>7.2.0</elasticsearch.version>
    <log4j.version>2.11.2</log4j.version>
    <junit.version>5.4.2</junit.version>
    <java.compiler.version>1.8</java.compiler.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.apache.oltu.oauth2</groupId>
        <artifactId>org.apache.oltu.oauth2.client</artifactId>
        <version>1.0.0</version>
    </dependency>
    <dependency>
        <groupId>org.wso2.carbon.identity</groupId>
        <artifactId>org.wso2.carbon.identity.oauth</artifactId>
        <version>5.0.7</version>
    </dependency>
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.1.1</version>
    </dependency>
    <dependency>
        <groupId>org.wso2.carbon</groupId>
        <artifactId>org.wso2.carbon.user.core</artifactId>
        <version>4.4.3</version>
    </dependency>
    <dependency>
		<groupId>org.apache.httpcomponents</groupId>
		<artifactId>httpclient</artifactId>
		<version>4.1.1</version>
	</dependency>
	<dependency>
	    <groupId>org.json</groupId>
	    <artifactId>json</artifactId>
	    <version>20180130</version>
	</dependency>
    <dependency>
         <groupId>org.elasticsearch.client</groupId>
         <artifactId>elasticsearch-rest-high-level-client</artifactId>
         <version>6.5.4</version>
    </dependency> 
     <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.4.2</version>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.4.2</version>
    </dependency>

</dependencies>

<repositories>
    <repository>
        <id>wso2-nexus</id>
        <name>WSO2 internal Repository</name>
        <url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
        <releases>
            <enabled>true</enabled>
            <updatePolicy>daily</updatePolicy>
            <checksumPolicy>ignore</checksumPolicy>
        </releases>
    </repository>
</repositories>

<build>
    <sourceDirectory>src/main/java</sourceDirectory>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <encoding>UTF-8</encoding>
                <optimize>true</optimize>
                <showDeprecation>true</showDeprecation>
                <showWarnings>true</showWarnings>
                <compilerArgument>-Xlint:all,-serial,-path,-rawtypes,-unchecked</compilerArgument>
            </configuration>
        </plugin>
    </plugins>
</build>

Elastic Java Client jar throwing this error when I load from wso2

Do you have all the dependencies of the client jar? The missing class is in the server jar, which is currently a dependency.

Yes I do.. It is working fine when I have tested on eclipse ie...,, elastic search java client sample.. But when I placed this jar in wso2 components lib.. its throwing error while restarting.,..

am really clueless on this..

@rjernst: Can you be more specific ?

The elastic search java client sample is working fine with same dependencies. But, its not working when I placed it in the wso2 components/lib ... its throwing error like that in starting the server?

@dadoonet:

Please find my pom.xml Sir..

<groupId>org.wso2.is</groupId>
<modelVersion>4.0.0</modelVersion>
<artifactId>custom-grant</artifactId>
<version>1.1.2</version>
<packaging>jar</packaging>
<name>OAuth 2.0 Custom Grant</name>
<url>http://maven.apache.org</url>

 <properties>
    <elasticsearch.version>7.2.0</elasticsearch.version>
    <log4j.version>2.11.2</log4j.version>
    <junit.version>5.4.2</junit.version>
    <java.compiler.version>1.8</java.compiler.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.apache.oltu.oauth2</groupId>
        <artifactId>org.apache.oltu.oauth2.client</artifactId>
        <version>1.0.0</version>
    </dependency>
    <dependency>
        <groupId>org.wso2.carbon.identity</groupId>
        <artifactId>org.wso2.carbon.identity.oauth</artifactId>
        <version>5.0.7</version>
    </dependency>
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.1.1</version>
    </dependency>
    <dependency>
        <groupId>org.wso2.carbon</groupId>
        <artifactId>org.wso2.carbon.user.core</artifactId>
        <version>4.4.3</version>
    </dependency>
    <dependency>
		<groupId>org.apache.httpcomponents</groupId>
		<artifactId>httpclient</artifactId>
		<version>4.1.1</version>
	</dependency>
	<dependency>
	    <groupId>org.json</groupId>
	    <artifactId>json</artifactId>
	    <version>20180130</version>
	</dependency>
    <dependency>
         <groupId>org.elasticsearch.client</groupId>
         <artifactId>elasticsearch-rest-high-level-client</artifactId>
         <version>6.5.4</version>
    </dependency> 
     <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.4.2</version>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.4.2</version>
    </dependency>

</dependencies>

<repositories>
    <repository>
        <id>wso2-nexus</id>
        <name>WSO2 internal Repository</name>
        <url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
        <releases>
            <enabled>true</enabled>
            <updatePolicy>daily</updatePolicy>
            <checksumPolicy>ignore</checksumPolicy>
        </releases>
    </repository>
</repositories>

<build>
    <sourceDirectory>src/main/java</sourceDirectory>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <encoding>UTF-8</encoding>
                <optimize>true</optimize>
                <showDeprecation>true</showDeprecation>
                <showWarnings>true</showWarnings>
                <compilerArgument>-Xlint:all,-serial,-path,-rawtypes,-unchecked</compilerArgument>
            </configuration>
        </plugin>
    </plugins>
</build>