title: NoClassDefFoundError joda DateTimeFormat using aws-kinesis on hadoop cloudera
body: <p>I got a strange error running aws kinesis on hadoop (CDH 5.5.1).</p>
  
  <p>I can reproduce the error with this simple class :</p>
  
  <pre><code>import com.amazonaws.auth.AWSCredentials;
  import com.amazonaws.auth.BasicAWSCredentials;
  import com.amazonaws.services.kinesis.AmazonKinesisClient;
  import org.apache.hadoop.conf.Configured;
  import org.apache.hadoop.util.Tool;
  import org.apache.hadoop.util.ToolRunner;
  import org.joda.time.format.DateTimeFormat;
  
  public class CollectJob extends Configured implements Tool {
  
      public static void main(String[] args) throws Exception {
  
          int exitCode = ToolRunner.run(new CollectJob(), args);
          System.exit(exitCode);
      }
  
      @Override
      public int run(String[] args) throws Exception {
  
          System.out.println(DateTimeFormat.class);
          System.out.println(DateTimeFormat.class.getProtectionDomain().getCodeSource().getLocation());
  
          System.out.println(AmazonKinesisClient.class);
          System.out.println(AmazonKinesisClient.class.getProtectionDomain().getCodeSource().getLocation());
  
          AWSCredentials credentials = new BasicAWSCredentials("toto", "tata");
          AmazonKinesisClient kinesisClient = new AmazonKinesisClient(credentials);
          kinesisClient.setEndpoint("kinesis.eu-west-1.amazonaws.com");
  
          return 0;
      }
  }
  </code></pre>
  
  <p>My pom :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="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"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;test&lt;/groupId&gt;
      &lt;artifactId&gt;event-collector&lt;/artifactId&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  
      &lt;repositories&gt;
      &lt;repository&gt;
          &lt;id&gt;cloudera-repo-releases&lt;/id&gt;
          &lt;url&gt;https://repository.cloudera.com/artifactory/repo/&lt;/url&gt;
      &lt;/repository&gt;
      &lt;/repositories&gt;
  
      &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.hadoop&lt;/groupId&gt;
          &lt;artifactId&gt;hadoop-common&lt;/artifactId&gt;
          &lt;version&gt;2.6.0-cdh5.5.1&lt;/version&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.hadoop&lt;/groupId&gt;
          &lt;artifactId&gt;hadoop-core&lt;/artifactId&gt;
          &lt;version&gt;2.6.0-mr1-cdh5.5.1&lt;/version&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.amazonaws&lt;/groupId&gt;
          &lt;artifactId&gt;aws-java-sdk&lt;/artifactId&gt;
          &lt;version&gt;1.7.4&lt;/version&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;joda-time&lt;/groupId&gt;
          &lt;artifactId&gt;joda-time&lt;/artifactId&gt;
          &lt;version&gt;2.4&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
              &lt;configuration&gt;
                  &lt;source&gt;1.7&lt;/source&gt;
                  &lt;target&gt;1.7&lt;/target&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-shade-plugin&lt;/artifactId&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;phase&gt;package&lt;/phase&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;shade&lt;/goal&gt;
                      &lt;/goals&gt;
                      &lt;configuration&gt;
                          &lt;transformers&gt;
                              &lt;transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer"/&gt;
                              &lt;transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"&gt;
                                  &lt;resource&gt;reference.conf&lt;/resource&gt;
                              &lt;/transformer&gt;
                          &lt;/transformers&gt;
                      &lt;/configuration&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>Then I run my main :</p>
  
  <pre><code>yarn jar event-collector-1.0-SNAPSHOT.jar CollectJob
  </code></pre>
  
  <p>And got this stdout :</p>
  
  <pre><code>class org.joda.time.format.DateTimeFormat
  file:/tmp/hadoop-unjar3521528256461676644/
  class com.amazonaws.services.kinesis.AmazonKinesisClient
  file:/opt/cloudera/parcels/CDH-5.5.1-1.cdh5.5.1.p0.11/jars/aws-java-sdk-1.7.4.jar
  Exception in thread "main" java.lang.NoClassDefFoundError: org/joda/time/format/DateTimeFormat
      at com.amazonaws.auth.AWS4Signer.&lt;clinit&gt;(AWS4Signer.java:44)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
      at java.lang.Class.newInstance(Class.java:374)
      at com.amazonaws.auth.SignerFactory.createSigner(SignerFactory.java:119)
      at com.amazonaws.auth.SignerFactory.lookupAndCreateSigner(SignerFactory.java:105)
      at com.amazonaws.auth.SignerFactory.getSigner(SignerFactory.java:78)
      at com.amazonaws.AmazonWebServiceClient.computeSignerByServiceRegion(AmazonWebServiceClient.java:307)
      at com.amazonaws.AmazonWebServiceClient.computeSignerByURI(AmazonWebServiceClient.java:280)
      at com.amazonaws.AmazonWebServiceClient.setEndpoint(AmazonWebServiceClient.java:160)
      at com.amazonaws.services.kinesis.AmazonKinesisClient.setEndpoint(AmazonKinesisClient.java:2102)
      at com.amazonaws.services.kinesis.AmazonKinesisClient.init(AmazonKinesisClient.java:216)
      at com.amazonaws.services.kinesis.AmazonKinesisClient.&lt;init&gt;(AmazonKinesisClient.java:139)
      at com.amazonaws.services.kinesis.AmazonKinesisClient.&lt;init&gt;(AmazonKinesisClient.java:116)
      at tivan.CollectJob.run(CollectJob.java:29)
      at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70)
      at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:84)
      at tivan.CollectJob.main(CollectJob.java:15)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
      at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
  Caused by: java.lang.ClassNotFoundException: org.joda.time.format.DateTimeFormat
      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)
      ... 26 more
  </code></pre>
  
  <p>I tried with either YARN_USER_CLASSPATH_FIRST true or false and get the same error.
  I don't understand what's wrong ...</p>
  
  <p>Help ! :)</p>
  
  <hr>
  
  <p>Edit with more details : also fail with :</p>
  
  <pre><code>    @Override
      public int run(String[] args) throws Exception {
  
          //print DateTimeFormat class infos
          System.out.println(DateTimeFormat.class);
          System.out.println(DateTimeFormat.class.getProtectionDomain().getCodeSource().getLocation());
  
          //print AWS4Signer class infos
          System.out.println(AWS4Signer.class);
          System.out.println(AWS4Signer.class.getProtectionDomain().getCodeSource().getLocation());
  
          //test joda time class (copy-paste from AWS4Signer source code)
          DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("yyyyMMdd").withZoneUTC();
          System.out.println(dateFormatter);
  
          //create AWS4Signer instance -&gt; ClassNotFound on DateTimeFormat !!!
          AWS4Signer signer = new AWS4Signer();
          System.out.println(signer);
  
          return 0;
      }
  </code></pre>