title: java.lang.NoClassDefFoundError: Could not initialize class
body: <p>I'm getting error <code>java.lang.NoClassDefFoundError</code> when running some tests <strong><em>only some times.</em></strong></p>
  
  <p>Here's the set up:
  Tests are written in Scala with services in Scala and Java. Using ant and ivy as well.</p>
  
  <p><strong>Order.scala</strong> looks something like this:</p>
  
  <pre><code>  object Order extends JdbcEnabled {
  
    val orderServiceClientIpAddress = Network.localIpAddress
    val PersonalOffersSaleId = "123"
    lazy val checkoutClient = new CheckoutClientImpl(YamlConfigFactory.loadConfig(
      this.getClass.getClassLoader.getResourceAsStream("core_config.yaml")
    ).getRequiredSubConfig("core").getRequiredSubConfig(Environment.HostEnv))
  
  
    val storeList = new JLinkedList[Store]()
    storeList.add(OrderHelper.getSelectedStore)
    var skuList = OrderHelper.getAvailableSkus
    val skusForInternationalOrders = skuList
  
  
    def createOrder(){...}}
  </code></pre>
  
  <p>There are many tests running with TestNG. Sometimes all the tests pass without any problem, but sometimes they fail with this exception.</p>
  
  <p>Here's a snippet of how a test calls Order api when it fails.</p>
  
  <pre><code>val orderNumber = Order.createOrder()
  </code></pre>
  
  <p>This is the <strong>entire</strong> stack trace when the test fails:</p>
  
  <pre><code>java.lang.NoClassDefFoundError: Could not initialize class com.api.Order$
      at com.CreateOrder.setUpOnce(CreateOrder.scala:35)
  </code></pre>
  
  <p>Line 35 in that class, CreateOrder.scala is:</p>
  
  <pre><code>val orderNumber = Order.createOrder()
  </code></pre>