title: SBT run differences between scala and java?
body: <p>I'm trying to follow the <a href="http://logging.apache.org/log4j/2.x/manual/configuration.html" rel="nofollow">log4j2 configuration tutorials</a> in a SBT 0.12.1 project. Here is my <em>build.sbt</em>:</p>
  
  <pre><code>name := "Logging Test"
  
  version := "0.0"
  
  scalaVersion := "2.9.2"
  
  libraryDependencies ++= Seq(
    "org.apache.logging.log4j" % "log4j-api" % "2.0-beta3",
    "org.apache.logging.log4j" % "log4j-core" % "2.0-beta3"
  )
  </code></pre>
  
  <p>I have two separate main classes. The first is <code>logtest.ScalaTest</code> in <em>src/main/scala/logtest/ScalaTest.scala</em>:</p>
  
  <pre><code>package logtest
  
  import org.apache.logging.log4j.{Logger, LogManager}
  
  object ScalaTest {
    private val logger = LogManager.getLogger(getClass())
    def main(args: Array[String]) {
      logger.trace("Entering application.")
      val bar = new Bar()
      if (!bar.doIt())
        logger.error("Didn't do it.")
  
      logger.trace("Exiting application.")
    }
  }
  </code></pre>
  
  <p>and the second is <code>logtest.JavaTest</code> in <em>src/main/java/logtest/JavaTest.java</em>:</p>
  
  <pre><code>package logtest;
  
  import org.apache.logging.log4j.Logger;
  import org.apache.logging.log4j.LogManager;
  
  public class JavaTest {
    private static Logger logger = LogManager.getLogger(JavaTest.class.getName());
  
    public static void main(String[] args) {
      logger.trace("Entering application.");
      Bar bar = new Bar();
  
      if (!bar.doIt())
        logger.error("Didn't do it.");
  
      logger.trace("Exiting application.");
    }
  }
  </code></pre>
  
  <p>If I run <code>logtest.ScalaTest.main()</code>  from inside sbt I get the output I was expecting given that <em>src/main/resources/log4j2.xml</em> sets the root logging level to trace:</p>
  
  <pre><code>&gt; run-main logtest.ScalaTest
  [info] Running logtest.ScalaTest 
  10:26:23.730 [run-main] TRACE logtest.ScalaTest$ - Entering application.
  10:26:23.733 [run-main] TRACE logtest.Bar -  entry
  10:26:23.733 [run-main] ERROR logtest.Bar - Did it again!
  10:26:23.733 [run-main] TRACE logtest.Bar -  exit with (false)
  10:26:23.733 [run-main] ERROR logtest.ScalaTest$ - Didn't do it.
  10:26:23.733 [run-main] TRACE logtest.ScalaTest$ - Exiting application.
  [success] Total time: 0 s, completed Dec 21, 2012 10:26:23 AM
  </code></pre>
  
  <p>However, when I run  <code>logtest.JavaTest.main()</code> from inside sbt I get different output</p>
  
  <pre><code>&gt; run-main logtest.JavaTest
  [info] Running logtest.JavaTest 
  ERROR StatusLogger Unable to locate a logging implementation, using SimpleLogger
  ERROR Bar Did it again!
  ERROR JavaTest Didn't do it.
  [success] Total time: 0 s, completed Dec 21, 2012 10:27:29 AM
  </code></pre>
  
  <p>From what I can tell, <code>ERROR StatusLogger Unable to ...</code> is usually a sign that log4j-core is not on my classpath. The lack of TRACE messages seems to indicate that my log4j2.xml settings aren't on the classpath either. Why should there be any difference in classpath if I'm running Foo.main versus LoggerTest.main? Or is there something else causing this behavior?</p>
  
  <h2>Update</h2>
  
  <p>I used SBT Assembly to build a fat jar of this project and specified logtest.JavaTest to be the main class. Running it from the command line produced correct results:</p>
  
  <pre><code>$ java -jar "Logging Test-assembly-0.0.jar" 
  10:29:41.089 [main] TRACE logtest.JavaTest - Entering application.
  10:29:41.091 [main] TRACE logtest.Bar -  entry
  10:29:41.091 [main] ERROR logtest.Bar - Did it again!
  10:29:41.091 [main] TRACE logtest.Bar -  exit with (false)
  10:29:41.091 [main] ERROR logtest.JavaTest - Didn't do it.
  10:29:41.091 [main] TRACE logtest.JavaTest - Exiting application.
  </code></pre>
  
  <h1>GitHub Example</h1>
  
  <p>Following Edmondo1984's suggestion, I put together a complete example and put it up on <a href="https://github.com/ecartner/sbt-run-log" rel="nofollow">github</a>.</p>