最近在學習Linux下sqoop連接hbase數據庫並導入數據時出現如下錯誤:
job: java.io.IOException: java.lang.reflect.InvocationTargetException
at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(Con nectionFactory.java:240)
at org.apache.hadoop.hbase.client.ConnectionManager.createConnection(Con nectionManager.java:410)
at org.apache.hadoop.hbase.client.ConnectionManager.createConnection(Con nectionManager.java:403)
at org.apache.hadoop.hbase.client.ConnectionManager.getConnectionInterna l(ConnectionManager.java:281)
at org.apache.hadoop.hbase.client.HBaseAdmin.<init>(HBaseAdmin.java:202)
at org.apache.sqoop.mapreduce.HBaseImportJob.jobSetup(HBaseImportJob.jav a:163)
at org.apache.sqoop.mapreduce.ImportJobBase.runImport(ImportJobBase.java :264)
at org.apache.sqoop.manager.SqlManager.importTable(SqlManager.java:668)
at org.apache.sqoop.manager.MySQLManager.importTable(MySQLManager.java:1 18)
at org.apache.sqoop.tool.ImportTool.importTable(ImportTool.java:497)
at org.apache.sqoop.tool.ImportTool.run(ImportTool.java:605)
at org.apache.sqoop.Sqoop.run(Sqoop.java:143)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70)
at org.apache.sqoop.Sqoop.runSqoop(Sqoop.java:179)
at org.apache.sqoop.Sqoop.runTool(Sqoop.java:218)
at org.apache.sqoop.Sqoop.runTool(Sqoop.java:227)
at org.apache.sqoop.Sqoop.main(Sqoop.java:236)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct orAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC onstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(Con nectionFactory.java:238)
... 16 more
Caused by: java.lang.NoClassDefFoundError: io/netty/channel/EventLoopGroup
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:274)
at org.apache.hadoop.conf.Configuration.getClassByNameOrNull(Configurati on.java:2051)
at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.jav a:2016)
at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:2110 )
at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:2136 )
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplement ation.<init>(ConnectionManager.java:631)
... 21 more
Caused by: java.lang.ClassNotFoundException: io.netty.channel.EventLoopGroup
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)
... 28 more
這個錯誤,出現之後困擾了我很久首先第一個錯誤java.lang.reflect.InvocationTargetException,這是一個Java反射異常,開始我還以為是哪一點配置出現錯誤了,所以這個問題一直困擾了我好久,後來進過自己的一步步測試發現,這個錯誤根本不是什麼配置的鍋,而是添加在環境中的hbase-client-*.jar這個包的問題,出現這個問題可能是你的這個jar包與你系統上裝的hbase和sqoop版本的問題
解決辦法:把hbase-client-*.jar換個版本,換高版本還是低版本,根據你裝hbase的來說然後第二個問題: java.lang.ClassNotFoundException: io.netty.channel.EventLoopGroup,這個問題很明顯是找不到這個類所導致的,而這個類是在netty-all.jar包下的
解決辦法:想你的hbase和sqoop環境中添加netty-all-4.0.23.Final.jar這個包,根據你裝的換版本,不過根據我的實驗,好像在低版本中,不需要添加這個包。上面這些希望對大家有幫助。。。