title: Finding Scala libraries location from within Scala program
body: <p>I'm trying to make one Scala program spawn another Scala program. I managed to obtain <code>java</code> executable from <code>System.getProperty("java.home")</code>, I've obtained some path from <code>System.getProperty("java.class.path")</code> (<code>sbt-launcher.jar</code> location), and with <code>ClassLoader</code> I've got <code>project/target/scala-2.11/classes</code> directory.</p>
  
  <p>However, I am still unable to run it. JVM complain that it is unable to find Scala library's classes:</p>
  
  <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: scala/concurrent/ExecutionContext
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
    at java.lang.Class.getMethod0(Class.java:3018)
    at java.lang.Class.getMethod(Class.java:1784)
    at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
      at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
  Caused by: java.lang.ClassNotFoundException: scala.concurrent.ExecutionContext
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      ... 7 more
  </code></pre>
  
  <p>I am looking for a way to add those files to classpath, but I want it to be portable. I do not look for solutions like hardcoding scala location on local computer nor do I want to use other environment variables and parameters than the one already existing. I also don't want to rely on SBT or Activators presence in user's environment.</p>
  
  <p>Since the parent JVM process can use them their location has to be stored somewhere and I'll be thankful for help with finding out that location.</p>