Java.lang.NoClassDefFoundError: Failed to initialize class

I get the java.lang.NoClassDefFoundError error when running some tests only a few times.

Configured here: Tests are written to Scala with services in Scala and Java. Using ant and ivy, too.

Order.scala looks something like this:

  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(){...}} 

There are many tests performed with TestNG. Sometimes all tests pass without any problems, but sometimes they fail with this exception.

Here's a snippet of how the test calls the Order api when it fails.

 val orderNumber = Order.createOrder() 

This stack trace is integer when the test fails:

 java.lang.NoClassDefFoundError: Could not initialize class com.api.Order$ at com.CreateOrder.setUpOnce(CreateOrder.scala:35) 

Line 35 in this class, CreateOrder.scala:

 val orderNumber = Order.createOrder() 
+4
source share
3 answers

This is probably not your whole class path, you should have the name of the missing class somewhere (perhaps after "called .."). Perhaps TestNG can be customized to show you full stack traces.

In any case, an initializer error means that the "Object Order" has thrown an exception in its constructor, so look what you are using there: maybe there are no JDBC classes? Or the configuration file that you get through the class loader?

+3
source

Your Order class looks like a proxy server. It is not initialized.

0
source

I think the problem is this:

  lazy val checkoutClient = new CheckoutClientImpl(YamlConfigFactory.loadConfig( this.getClass.getClassLoader.getResourceAsStream("core_config.yaml") ).getRequiredSubConfig("core").getRequiredSubConfig(Environment.HostEnv)) 

As stated here and here , it seems to be a getClassLoader problem or class path.

0
source

Source: https://habr.com/ru/post/1440956/


All Articles