I need to use two different versions of jar of same package in my code. So that i have used JarClassLoader to achieve the same
But I ended with ClassNotFoundException
I have given below my code
Below is the executable Main class file
import java.lang.reflect.Method;
import org.xeustechnologies.jcl.JarClassLoader;
import org.xeustechnologies.jcl.JclObjectFactory;
import org.xeustechnologies.jcl.JclUtils;
public class Sam {
public static void main(String args[]) {
try{
JarClassLoader jcl = new JarClassLoader();
jcl.add("/Users/sd/Downloads/hbase-1.2.6/lib/");
Object obj1 = JclObjectFactory.getInstance().create(jcl, "sample.InsertData");
Insert mig = JclUtils.cast(obj1, Insert.class);
Thread.currentThread().setContextClassLoader(jcl);
Method method = Insert.class.getMethod("insert", new Class[]{});
method.invoke(mig, args);
}catch(Exception e) {
e.printStackTrace();
}
}
}
InsertData.java
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;
public class InsertData implements Insert{
public void insert() throws IOException {
for (int j = 0; j < 1; j++) {
Configuration config = HBaseConfiguration.create();
On executing Sam I ended with below java.lang.ClassNotFoundException
java sample/Sam
java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at sample.Sam.main(Sam.java:21) Caused by: java.lang.reflect.UndeclaredThrowableException at com.sun.proxy.$Proxy0.insert(Unknown Source) ... 5 more Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.xeustechnologies.jcl.proxy.JdkProxyProvider$JdkProxyHandler.invoke(JdkProxyProvider.java:56) ... 6 more Caused by: java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/HBaseConfiguration at sample.InsertData.insert(InsertData.java:27) ... 11 more Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.HBaseConfiguration 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) ... 12 more
Please help
Aucun commentaire:
Enregistrer un commentaire