Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/ipc/RpcControllerFactory

Highlighted

java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/ipc/RpcControllerFactory

New Contributor

package hbasePhxPOC.hbasePhx;

import java.sql.*;

import java.util.Properties;

import org.apache.phoenix.jdbc.PhoenixDriver;

public class PhoenixExample {

public static void main(String[] args) {

// Create variables

Connection connection = null;

Statement statement = null;

ResultSet rs = null;

PreparedStatement ps = null;

Properties conf = new Properties();

try {

Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");

connection = DriverManager.getConnection("jdbc:phoenix:sandbox-hdp.hortonworks.com:2181:/hbase-unsecure");

conf.put("hbase.zookeeper.quorum", "sandbox-hdp.hortonworks.com");

conf.put("hbase.zookeeper.property.clientPort", "2181");

conf.put("zookeeper.znode.parent", "/hbase");

// Connect to the database

//connection = DriverManager.getConnection("jdbc:phoenix:sandbox-hdp.hortonworks.com",conf);

//connection = DriverManager.getConnection(conf);

// Create a JDBC statement

statement = connection.createStatement();

// Execute our statements

statement.executeUpdate("create table javatest (mykey integer not null primary key, mycolumn varchar)");

statement.executeUpdate("upsert into javatest values (1,'Hello')");

statement.executeUpdate("upsert into javatest values (2,'Java Application')");

connection.commit();

// Query for table

ps = connection.prepareStatement("select * from javatest");

rs = ps.executeQuery();

System.out.println("Table Values");

while(rs.next()) {

Integer myKey = rs.getInt(1);

String myColumn = rs.getString(2);

System.out.println("\tRow: " + myKey + " = " + myColumn);

}

}

catch(SQLException e) {

e.printStackTrace();

} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

finally {

if(ps != null) {

try {

ps.close();

}

catch(Exception e) {}

}

if(rs != null) {

try {

rs.close();

}

catch(Exception e) {}

}

if(statement != null) {

try {

statement.close();

}

catch(Exception e) {}

}

if(connection != null) {

try {

connection.close();

}

catch(Exception e) {}

}

}

}

}

****************

pom.xml

<projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>hbasePhxPOC</groupId>

<artifactId>hbasePhx</artifactId>

<version>0.0.1-SNAPSHOT</version>

<packaging>jar</packaging>

<name>hbasePhx</name>

<url>http://maven.apache.org</url>

<properties>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

</properties>

<dependencies>

<dependency>

<groupId>org.apache.phoenix</groupId>

<artifactId>phoenix-core</artifactId>

<version>4.6.0-HBase-1.1</version>

</dependency>

<dependency>

<groupId>com.google.api-client</groupId>

<artifactId>google-api-client</artifactId>

<version>1.20.0</version>

</dependency>

<dependency>

<groupId>com.google.http-client</groupId>

<artifactId>google-http-client-xml</artifactId>

<version>1.22.0</version>

</dependency>

</dependencies>

</project>

Getting Below Exception:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/ipc/RpcControllerFactory

at java.lang.ClassLoader.defineClass1(Native Method)

at java.lang.ClassLoader.defineClass(ClassLoader.java:763)

at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)

at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)

at java.net.URLClassLoader.access$100(URLClassLoader.java:73)

at java.net.URLClassLoader$1.run(URLClassLoader.java:368)

at java.net.URLClassLoader$1.run(URLClassLoader.java:362)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:361)

at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)

at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

at org.apache.phoenix.query.QueryServicesOptions.<clinit>(QueryServicesOptions.java:193)

at org.apache.phoenix.query.QueryServicesImpl.<init>(QueryServicesImpl.java:36)

at org.apache.phoenix.jdbc.PhoenixDriver.getQueryServices(PhoenixDriver.java:130)

at org.apache.phoenix.jdbc.PhoenixDriver.getConnectionQueryServices(PhoenixDriver.java:163)

at org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.connect(PhoenixEmbeddedDriver.java:132)

at org.apache.phoenix.jdbc.PhoenixDriver.connect(PhoenixDriver.java:151)

at java.sql.DriverManager.getConnection(DriverManager.java:664)

at java.sql.DriverManager.getConnection(DriverManager.java:270)

at hbasePhxPOC.hbasePhx.PhoenixExample.main(PhoenixExample.java:20)

Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.ipc.RpcControllerFactory

at java.net.URLClassLoader.findClass(URLClassLoader.java:381)

at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)

at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

... 21 more

Don't have an account?
Coming from Hortonworks? Activate your account here