java - 朱尼特 : Exception while creating BOFactory instance

标签 java eclipse junit

我正在尝试在 IID8.5 上设置 JUnit 框架。但是当我尝试运行简单的 JUnit 测试用例时,我收到运行时错误。 (java.lang.NoClassDefFoundError: org.eclipse.core.runtime.RegistryFactory)

我正在使用 JUnit4。 Please find attached image showing project structure

**BOUtils.java 中的代码**

package com.wf.utils;
import com.ibm.websphere.bo.BOFactory;
import com.ibm.websphere.sca.ServiceManager;
import com.ibm.websphere.sca.Service.*;

public class BOUtils {

/**
 * @param args
 */

public static void createBusinessObject()
{
    System.out.println("Create  Business Object");
    BOFactory boFactory = (BOFactory) new    ServiceManager().locateService("com/ibm/websphere/bo/BOFactory");
}
public static void main(String[] args) {
    // TODO Auto-generated method stub

}

}

**Code in JunitTest.java**

package JunitTest;
import junit.framework.TestCase;
import com.wf.utils.BOUtils;
import org.junit.Test;


   public class JunitTest extends TestCase {
   @Test
   public void testPersistCust()
  {
     System.out.println("testPersistCust");
     BOUtils.createBusinessObject();
  }
}  


**Exception Stack Trace**
 java.lang.NoClassDefFoundError: org.eclipse.core.runtime.RegistryFactory
at       org.eclipse.core.internal.runtime.InternalPlatform.getRegistry(InternalPlatform.java:671)
at org.eclipse.core.runtime.Platform.getExtensionRegistry(Platform.java:867)
at com.ibm.wsspi.sca.extensions.ServiceProviderRegistry.loadServiceProviders(ServiceProviderRegistry.java:167)
at com.ibm.wsspi.sca.extensions.ServiceProviderRegistry$1.run(ServiceProviderRegistry.java:88)
at java.security.AccessController.doPrivileged(AccessController.java:202)
at com.ibm.wsspi.sca.extensions.ServiceProviderRegistry.getServiceProviders(ServiceProviderRegistry.java:86)
at com.ibm.wsspi.sca.extensions.ServiceProviderRegistry.getServiceProvider(ServiceProviderRegistry.java:101)
at com.ibm.ws.sca.resources.loader.ClassLoaderRegistry.<clinit>(ClassLoaderRegistry.java:59)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
at com.ibm.ws.sca.internal.container.impl.ContainerImpl.<clinit>(ContainerImpl.java:343)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
at com.ibm.ws.sca.internal.container.impl.ContainerFactoryImpl.createContainer(ContainerFactoryImpl.java:70)
at com.ibm.ws.sca.internal.container.Container.<clinit>(Container.java:111)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
at com.ibm.ws.sca.internal.manager.impl.ServiceManagerImpl.<init>(ServiceManagerImpl.java:68)
at java.lang.J9VMInternals.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1325)
at com.ibm.websphere.sca.ServiceManager$InstanceCreator.create(ServiceManager.java:53)
at com.ibm.websphere.sca.ServiceManager$InstanceCreator.access$000(ServiceManager.java:43)
at com.ibm.websphere.sca.ServiceManager.<clinit>(ServiceManager.java:73)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
at BOUtils.createBusinessObject(BOUtils.java:14)
at JunitTest.testPersistCust(JunitTest.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:599)
at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.lang.ClassNotFoundException: org.eclipse.core.runtime.RegistryFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:419)
at java.lang.ClassLoader.loadClass(ClassLoader.java:643)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:345)
at java.lang.ClassLoader.loadClass(ClassLoader.java:609)
... 47 more

任何帮助将不胜感激。如果需要任何其他信息,请告诉我。

问候, 研发

最佳答案

该异常告诉您某个类对于您正在其中运行的 JVM 不可用。

简单的答案:然后开始搜索该类......你可以找到这个 here - 您可以在其中下载各种与 eclipse 相关的 JAR。

因此:尝试一下如果将 org-eclipse-equinox-registry.jar 添加到类路径中会发生什么情况。

(此 here 可能包含对正在发生的事情的解释)

关于java - 朱尼特 : Exception while creating BOFactory instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42239589/

相关文章:

java - 业务方法中的错误检查,也就是进行防御性编程

java - 在 Java/Android 中附加 .aac 文件

java - Java 中长期运行的数据处理系统的通用架构?

java - 模型对话框 - Swing 。仅阻止对 UI 某些部分的输入

java - 是否有构建 64 位 JD2XX DLL 的简单方法?

eclipse - Eclipse CDT 中的 C++14 语法可以编译但标记为语法错误(索引器)

eclipse - Scala IDE 在自动完成提示期间不显示文档

java - 如何使用命令行将 p2 更新站点的所有功能安装到 Eclipse?

android-studio - Android Studio :Null pointer exception when assembleDebugUnitTest gradle task is run

java - 如何在略有不同的 jar 列表上运行测试用例?