title: Intellij Maven: Create jar with all library dependencies
body: <p>Working with IntelliJ Idea, I want to implement the following:</p>
  
  <p>I want to export an application to a jar, which contains all needed libraries. E.g. I need the AWS Java SDK libraries for S3 access, but if I upload the jar to the server and run the jar I get an NoClassDefFoundError, see below:</p>
  
  <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: com/amazonaws/auth/AWSCredentials
      at java.lang.Class.getDeclaredMethods0(Native Method)
      at java.lang.Class.privateGetDeclaredMethods(Class.java:2625)
      at java.lang.Class.getMethod0(Class.java:2866)
      at java.lang.Class.getMethod(Class.java:1676)
      at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
      at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
  Caused by: java.lang.ClassNotFoundException: com.amazonaws.auth.AWSCredentials
      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)
      ... 6 more
  </code></pre>
  
  <p>Comparison: I created the same project in Eclipse and get no error! The jar file sizes are very different (Eclipse: ~35 MB vs. IntelliJ Idea: ~5,5 MB)! </p>
  
  <p>I included the libraries via Maven and downloaded them also into the "lib" folder of my project:
  <a href="https://i.stack.imgur.com/sfJ4o.png" rel="noreferrer"><img src="https://i.stack.imgur.com/sfJ4o.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/pFvao.png" rel="noreferrer"><img src="https://i.stack.imgur.com/pFvao.png" alt="enter image description here"></a></p>
  
  <p>As parameter in the run configurations I set "package", see screenshot below:
  <a href="https://i.stack.imgur.com/6mbaE.png" rel="noreferrer"><img src="https://i.stack.imgur.com/6mbaE.png" alt="enter image description here"></a></p>
  
  <p><strong>SOLUTION:</strong></p>
  
  <p>Thanks for all your hints, I got it to work now! The trick was that I did't add the dependencies to the pom.xml file (because I thought that this would be done automatically after setting them in the Project Structure, but it didn't)!!! See also my other question: <a href="https://stackoverflow.com/questions/34088277/intellij-idea-maven-plugin-manage-dependencies">Intellij IDEA Maven Plugin - Manage Dependencies</a> and <a href="https://www.jetbrains.com/idea/help/maven.html" rel="noreferrer">https://www.jetbrains.com/idea/help/maven.html</a>! Add the dependencies by </p>
  
  <ol>
  <li>Open pom.xml</li>
  <li>Menu "Code" > "Generate" > "Dependency" (or shortcut ALT + INSERT)</li>
  </ol>