ND4J with JUnit 4 error

When I call ND4J from my JUnit test, I got the following error (see below). The same code runs just fine outside the JUnit. Anyone saw similar issue? What might be the cause of it? Thanks for info.

java.lang.ExceptionInInitializerError
at org.deeplearning4j.nn.conf.MultiLayerConfiguration$Builder.build(MultiLayerConfiguration.java:719)
at org.deeplearning4j.nn.conf.NeuralNetConfiguration$ListBuilder.build(NeuralNetConfiguration.java:258)
at com.amyoung.idea.forecast.DailyHighLow.buildSequentialModel(DailyHighLow.java:187)
at com.amyoung.idea.forecast.DailyHighLow.train(DailyHighLow.java:283)
at com.amyoung.idea.forecast.DailyHighLow.train(DailyHighLow.java:321)
at com.amyoung.idea.forecast.EvaluatorTest.testSaveLoad(EvaluatorTest.java:62)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:542)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:770)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:464)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
Caused by: java.lang.RuntimeException: failed to process available backends
at org.nd4j.linalg.factory.Nd4jBackend.load(Nd4jBackend.java:167)
at org.nd4j.linalg.factory.Nd4j.initContext(Nd4j.java:5128)
at org.nd4j.linalg.factory.Nd4j.(Nd4j.java:226)
… 31 more
Caused by: java.util.ServiceConfigurationError: org.nd4j.linalg.factory.Nd4jBackend: org.nd4j.linalg.jblas.JblasBackend Unable to get public no-arg constructor
at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:583)
at java.base/java.util.ServiceLoader.getConstructor(ServiceLoader.java:674)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1233)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1265)
at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1300)
at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1385)
at org.nd4j.linalg.factory.Nd4jBackend.load(Nd4jBackend.java:161)
… 33 more
Caused by: java.lang.NoClassDefFoundError: org/springframework/core/io/Resource
at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3138)
at java.base/java.lang.Class.getConstructor0(Class.java:3343)
at java.base/java.lang.Class.getConstructor(Class.java:2152)
at java.base/java.util.ServiceLoader$1.run(ServiceLoader.java:661)
at java.base/java.util.ServiceLoader$1.run(ServiceLoader.java:658)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:554)
at java.base/java.util.ServiceLoader.getConstructor(ServiceLoader.java:669)
… 38 more
Caused by: java.lang.ClassNotFoundException: org.springframework.core.io.Resource
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
… 46 more

It looks like this is the initial cause of the problem here. I see that you are running the test with Eclipse, you should probably make sure that it properly imported your maven project and all of your project dependencies are set up right.

Paul,

Thanks for the pointer. I miss configured the dependency for the JUnit. I was using Gradle build in Eclipse. I had a wrong testCompile dependency in my “build.gradle” file.

Jin