Unable to add UDF in hive
<p>I have to add the following UDF in hive :</p>

<pre><code>package com.hadoopbook.hive;

import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text;

public class Strip extends UDF {
  private Text result = new Text();

  public Text evaluate(Text str) {
    if (str == null) {
      return null;
    }
    result.set(StringUtils.strip(str.toString()));
    return result;
  }

  public Text evaluate(Text str, String stripChars) {
    if (str == null) {
      return null;
    }
    result.set(StringUtils.strip(str.toString(), stripChars));
    return result;
  }
}
</code></pre>

<p>This is an example from the book "Hadoop : The definitive guide"</p>

<ol>
<li><p>I created the <code>.class</code> file of above java file using the following command :</p>

<pre><code>hduser@nb-VPCEH35EN:~/Hadoop-tutorial/hadoop-book-master/ch17-hive/src/main/java/com/hadoopbook/hive$ javac Strip.java 
</code></pre></li>
<li><p>Then I created the jar file using the following command :</p>

<pre><code>hduser@nb-VPCEH35EN:~/Hadoop-tutorial/hadoop-book-master/ch17-hive/src/main/java/com/hadoopbook/hive$ jar cvf Strip.jar Strip Strip.class 
Strip : no such file or directory
added manifest
adding: Strip.class(in = 915) (out= 457)(deflated 50%)
</code></pre></li>
<li><p>I added the geenrated jar file to hdfs directory with :</p>

<pre><code>hduser@nb-VPCEH35EN:~/Hadoop-tutorial/hadoop-book-master/ch17-hive/src/main/java/com/hadoopbook/hive$ hadoop dfs -copyFromLocal /home/hduser/Hadoop-tutorial/hadoop-book-master/ch17-hive/src/main/java/com/hadoopbook/hive/Strip.jar /user/hduser/input
</code></pre></li>
<li><p>I tried to create a UDf usign the following command :</p>

<pre><code>hive&gt; create function strip as 'com.hadoopbook.hive.Strip' using jar 'hdfs://localhost/user/hduser/input/Strip.jar';
</code></pre></li>
</ol>

<p>But I got an error as following :</p>

<blockquote>
  <p>converting to local hdfs://localhost/user/hduser/input/Strip.jar Added
  [/tmp/hduser_resources/Strip.jar] to class path Added resources:
  [hdfs://localhost/user/hduser/input/Strip.jar] Failed to register
  default.strip using class com.hadoopbook.hive.Strip FAILED: Execution
  Error, return code 1 from org.apache.hadoop.hive.ql.exec.FunctionTask</p>
</blockquote>

<ol start="5">
<li><p>I also tried to create temporary function.
So I first added the jar file to hive using  :</p>

<pre><code>hive&gt; add jar hdfs://localhost/user/hduser/input/Strip.jar;
converting to local hdfs://localhost/user/hduser/input/Strip.jar
Added [/tmp/hduser_resources/Strip.jar] to class path
Added resources: [hdfs://localhost/user/hduser/input/Strip.jar]
</code></pre></li>
<li><p>Then I tried to add the temporary function :</p>

<pre><code>hive&gt; create temporary function strip as 'com.hadoopbook.hive.Strip';
</code></pre></li>
</ol>

<p>But I got the following error :</p>

<blockquote>
  <p>FAILED: Class com.hadoopbook.hive.Strip not found FAILED: Execution
  Error, return code 1 from org.apache.hadoop.hive.ql.exec.FunctionTask</p>
</blockquote>

<p>The jar file was successully created and added to hive.Still it is showing that class not found.
Can anyone please tell what is wrong with it ?</p>