本文介绍了Junit:创建BOFactory实例时异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我正在使用JUnit4。



** 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(创建业务对象);
BOFactory boFactory =(BOFactory)new ServiceManager()。locateService(com / ibm / websphere / bo / BOFactory);
}
public static void main(String [] args){
// TODO自动生成的方法存根

}

}

** JunitTest.java中的代码**

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


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


**异常堆栈跟踪**
java.lang.NoClassDefFoundError:org.eclipse.core.runtime.RegistryFactory
在org.eclipse.core.internal.runtime.InternalPlatform.getRegistry(InternalPlatform.java:671)
在org.eclipse.core.runtime.Platform.getExtensionRegistry(Platform.java:867)
在com.ibm.wsspi.sca.extensions.ServiceProviderRegistry.loadServiceProviders(ServiceProviderRegistry.java:167)
在com.ibm.wsspi.sca.extensions.ServiceProviderRegistry $ 1.run(ServiceProviderRegistry.java:88)
在java.security.AccessController.doPrivileged(AccessController.java:202)
在com.ibm.wsspi.sca.extensions.ServiceProviderRegistry.getServiceProviders(ServiceProviderRegistry.java:86)
在com.ibm。 wsspi.sca.extensions.ServiceProviderRegistry.getServiceProvider(ServiceProviderRegistry.java:101)
at com.ibm.ws.sca.resources.loader.ClassLoaderRegistry。< clinit>(ClassLoaderRegistry.java:59)
在java.lang.J9VMInternals.initializeImpl( Native方法)
在java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
在com.ibm.ws.sca.internal.container.impl.ContainerImpl。< clinit>(ContainerImpl。 java:343)
在java.lang.J9VMInternals.initializeImpl(本机方法)
在java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
在com.ibm.ws. sca.internal.container.impl.ContainerFactoryImpl.createContainer(ContainerFactoryImpl.java:70)
at com.ibm.ws.sca.internal.container.Container。< clinit>(Container.java:111)
在java.lang.J9VMInternals.initializeImpl(本机方法)
在java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
在com.ibm.ws.sca.internal.manager。 impl.ServiceManagerImpl。< init>(ServiceManagerImpl.java:68)
在java.lang.J9VMInternals.newInstanceImpl(Native Method)
在java.lang.Class.newInstance(Class.java:1325)
在com.ibm.websphere.sca.ServiceManager $ InstanceCreator.create(ServiceManager.java:53)
在com.ibm.websphere.sca.ServiceManager $ I nstanceCreator.access $ 000(ServiceManager.java:43)
at com.ibm.websphere.sca.ServiceManager。< clinit>(ServiceManager.java:73)
在java.lang.J9VMInternals.initializeImpl( Native方法)
在java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
在BOUtils.createBusinessObject(BOUtils.java:14)
在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( DelegatingMethodMethodAccessorImpl.java:37)
在java.lang.reflect.Method.invoke(Method.java:599)
在org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
在org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
在org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
在org.junit.internal.runners.Te stMethodRunner.runMethod(TestMethodRunner.java:75)
在org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
在org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod( TestClassMethodsRunner.java:66)
在org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
在org.junit.internal.runners.TestClassRunner $ 1.runUnprotected(TestClassRunner.java :42)
在org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
在org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)$在$ org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java)中的
:38)
在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (RemoteTestRunner.java:673)
在o rg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
导致:java.lang.ClassNotFoundException:org.eclipse.core.runtime.RegistryFactory
在java.net.URLClassLoader.findClass(URLClassLoader.java:419)
在java.lang.ClassLoader .loadClass(ClassLoader.java:643)
at sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:345)
在java.lang.ClassLoader.loadClass(ClassLoader.java:609)
... 47更多

任何帮助将非常感激。让我知道是否需要任何附加信息。



Regards,
RD

解决方案

该异常告诉您某个类不适用于您正在运行的JVM。



简单的答案是:然后开始搜索类...你可以在这里找到这个新新新200新新旗新新旗新新旗新新旗新新旗新新旗新新旗旗哨旗新200



因此:尝试如果您的类路径中有org-eclipse-equinox-registry.jar会发生什么。



(此可能会说明发生了什么新新p新新旗新新新旗新新旗旗新新旗新新旗旗新新旗旗哨旗新新新旗新新旗旗

I am trying to setup JUnit framework on IID8.5. But when I am trying to run simple JUnit testcase I am receiving runtime error. (java.lang.NoClassDefFoundError: org.eclipse.core.runtime.RegistryFactory)

I am using JUnit4.Please find attached image showing project structure

**Code in 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

Any help will be highly appreciated. Let me know if any addtional information is required.

Regards,RD

解决方案

That exception tells you that a certain class is not available to the JVM you are running this within.

The simple answer: then start searching that class ... and you could find this here - where you can download various eclipse related JARs.

Thus: try what happens if you org-eclipse-equinox-registry.jar to your classpath.

( This here might contain an explanation of what is going on )

这篇关于Junit:创建BOFactory实例时异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 19:01