Sqoop Job Failed with Error: java.lang.NoClassDefFoundError: org/json/JSONObject

Sqoop Job Failed with Error: java.lang.NoClassDefFoundError: org/json/JSONObject

If your Sqoop job fails with below error message:

Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONObject
at org.apache.sqoop.util.SqoopJsonUtil.getJsonStringforMap(SqoopJsonUtil.java:42)
at org.apache.sqoop.SqoopOptions.writeProperties(SqoopOptions.java:742)
at org.apache.sqoop.mapreduce.JobBase.putSqoopOptionsToConfiguration(JobBase.java:369)
at org.apache.sqoop.mapreduce.JobBase.createJob(JobBase.java:355)
at org.apache.sqoop.mapreduce.ImportJobBase.runImport(ImportJobBase.java:249)
at org.apache.sqoop.manager.SqlManager.importQuery(SqlManager.java:748)
at org.apache.sqoop.tool.ImportTool.importTable(ImportTool.java:509)
at org.apache.sqoop.tool.ImportTool.run(ImportTool.java:615)
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.ClassNotFoundException: org.json.JSONObject
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)
... 14 more

This is very likely caused by conflicting JAR files being loaded by sqoop, and mostly related to JAR files under /usr/lib/hive directory, which is normally created by package installation of Sqoop, rather than via Parcels through Cloudera Manager.

The solution is to remove /usr/lib/hive directory completely, assuming that you are using Parcel installation version of CDH via Cloudera Manager.

If you have JAR files that are needed by HiveServer via “Auxiliary JARs Directory”, suggestion is to update the Auxiliary directory to another location and copy the required JAR files across. To do so, please go to CM > Hive > Configuration > “Hive Auxiliary JARs Directory”, and change its location to somewhere else, for example, “/hive/jars”, and the copy JAR files across.

Please keep in mind that the /hive/jars directory and JAR files need to be created on ALL HiveServer2 hosts, otherwise the host that is missing those will fail to start.

After that, Sqoop should be able to run import command as usual.

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *

My new Snowflake Blog is now live. I will not be updating this blog anymore but will continue with new contents in the Snowflake world!