title: How to fix Exception in thread "main" java.lang.NoClassDefFoundError: com/itextpdf/text/DocumentException
body: <p>I created a console application. This app can generate a pdf. I use itextpdf. I added in build gradle:</p>
  
  <pre><code>compile group: 'com.itextpdf', name: 'itextpdf', version: '5.5.10'
  </code></pre>
  
  <p>When I start my program in command line I see a this log: </p>
  
  <pre><code>Error: A JNI error has occurred, please check your installation and try again
  Exception in thread "main" java.lang.NoClassDefFoundError: com/itextpdf/text/DocumentException
          at java.lang.Class.getDeclaredMethods0(Native Method)
          at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
          at java.lang.Class.privateGetMethodRecursive(Unknown Source)
          at java.lang.Class.getMethod0(Unknown Source)
          at java.lang.Class.getMethod(Unknown Source)
          at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
          at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
  Caused by: java.lang.ClassNotFoundException: com.itextpdf.text.DocumentException
          at java.net.URLClassLoader.findClass(Unknown Source)
          at java.lang.ClassLoader.loadClass(Unknown Source)
          at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
          at java.lang.ClassLoader.loadClass(Unknown Source)
          ... 7 more
  </code></pre>
  
  <p>When I start my app in IntelliJ it works corretly.</p>
  
  <p>build.gradle :</p>
  
  <pre><code>      group 'Harmonogramy'
  version '1.0-SNAPSHOT'
  
  task wrapper(type: Wrapper) {
    gradleVersion = '3.1'
    distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
  }
  
  apply plugin: 'java'
  
  sourceCompatibility = 1.5
  
  repositories {
      mavenCentral()
  }
  
  dependencies {
      testCompile group: 'junit', name: 'junit', version: '4.11'
      // https://mvnrepository.com/artifact/mysql/mysql-connector-java
      compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.34'
      // https://mvnrepository.com/artifact/commons-dbutils/commons-dbutils
      compile group: 'commons-dbutils', name: 'commons-dbutils', version: '1.6'
  // https://mvnrepository.com/artifact/org.apache.commons/commons-csv
      compile group: 'org.apache.commons', name: 'commons-csv', version: '1.4'
      // https://mvnrepository.com/artifact/com.itextpdf/itextpdf
      compile group: 'com.itextpdf', name: 'itextpdf', version: '5.5.10'
  // https://mvnrepository.com/artifact/net.sf.opencsv/opencsv
      compile group: 'net.sf.opencsv', name: 'opencsv', version: '2.3'
  
  }
  
  jar {
      archiveName = 'Harmonogramy.jar'
  
      manifest {
          attributes 'Main-Class': 'Main',
                  'Class-Path': configurations.runtime.files.collect { "lib/$it.name" }.join(' '),
                  'Implementation-Version': version
      }
  
      from(configurations.compile.collect { it.isDirectory() ? it : zipTree(it) })
  }
  </code></pre>