title: How to run jar generated by package (possibly with other jars under lib)?
body: <p>How can I run <code>.jar</code> file which is generated by sbt's <code>package</code>?</p>
  
  <p>I created a really simple example with a single <code>.scala</code> source:</p>
  
  <pre><code>package org.pack {
      class ScalaParser(files: Array[String]) {
          def doAll() = {
              println("hello")
          }
      }
  
      object Main {
          def main(args: Array[String]): Unit = {
              val sp = new ScalaParser(args)
              sp.doAll()
          }
  
      }
  }
  </code></pre>
  
  <p>After running</p>
  
  <pre><code>$ sbt
  &gt; compile
  &gt; package
  </code></pre>
  
  <p><code>.jar</code> is created in <code>/target/scala-&lt;version&gt;</code>. If I try to run it, it fails giving this error:</p>
  
  <pre><code>$ java -jar package_2.9.2-0.1.jar 
  Exception in thread "main" java.lang.NoClassDefFoundError: scala/ScalaObject
      at java.lang.ClassLoader.defineClass1(Native Method)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
      at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
      at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
      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)
      at org.pack.Main.main(Main.scala)
  Caused by: java.lang.ClassNotFoundException: scala.ScalaObject
      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)
      ... 13 more
  </code></pre>
  
  <p>Note that no external libraries are used and <code>sbt compile run</code> works fine.</p>
  
  <p>I attached <a href="https://www.dropbox.com/sh/0b663mewxt83c85/AAAsRl1DoThtzEcZlxOCi7Vca/package.zip" rel="noreferrer">the whole project including generated .jar on dropbox</a>.</p>
  
  <p>What is really weird is the fact that <code>.jar</code> Manifest contains right class to load, i.e. <code>org.pack.Main</code>. Maybe it is caused by something else.</p>
  
  <p><strong>System info</strong></p>
  
  <pre><code>$ java -version
  java version "1.7.0_55"
  OpenJDK Runtime Environment (IcedTea 2.4.7) (7u55-2.4.7-1ubuntu1)
  OpenJDK 64-Bit Server VM (build 24.51-b03, mixed mode)
  
  $ scala -version
  Scala code runner version 2.9.2 -- Copyright 2002-2011, LAMP/EPFL
  </code></pre>
  
  <p><strong>Additional question</strong> - what if I had some external <code>.jar</code>s in <code>/lib</code>? How can I assure that they are packed? I need one <code>.jar</code> runnable on (possibly) every JVM.</p>
  
  <p>Thanks for help.</p>