代码之家  ›  专栏  ›  技术社区  ›  Student

带描述符的简单无状态:ClassNotFoundException:LocalInitialContextFactory

  •  0
  • Student  · 技术社区  · 10 年前

    我开始学习EJB,并尝试运行示例: http://openejb.apache.org/examples-trunk/simple-stateless-with-descriptor/README.html

    javax.naming.NoInitialContextException: Cannot instantiate class: simpleStatelessWithDescriptor.LocalInitialContextFactory [Root exception is java.lang.ClassNotFoundException: simpleStatelessWithDescriptor.LocalInitialContextFactory]
        at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657)
        at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
        at javax.naming.InitialContext.init(InitialContext.java:223)
        at javax.naming.InitialContext.<init>(InitialContext.java:197)
        at simpleStatelessWithDescriptor.CalculatorTest.setUp(CalculatorTest.java:17)
        at junit.framework.TestCase.runBare(TestCase.java:139)
        at junit.framework.TestResult$1.protect(TestResult.java:122)
        at junit.framework.TestResult.runProtected(TestResult.java:142)
        at junit.framework.TestResult.run(TestResult.java:125)
        at junit.framework.TestCase.run(TestCase.java:129)
        at junit.framework.TestSuite.runTest(TestSuite.java:252)
        at junit.framework.TestSuite.run(TestSuite.java:247)
        at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
    Caused by: java.lang.ClassNotFoundException: simpleStatelessWithDescriptor.LocalInitialContextFactory
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:249)
        at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:46)
        at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654)
        ... 18 more
    

    我的文件树是:

    enter image description here

    我搜索并替换了所有文件中的包名称,以符合文件树。

    现在,还缺少什么?为什么找不到LocalInitialContextFactory?

    我使用的是Windows 10 64位、Eclipse Neon、java 6(目前无法更新)。

    1 回复  |  直到 10 年前
        1
  •  0
  •   davidxxx    10 年前

    simpleStatelessWithDescriptor.LocalInitialContextFactory 不存在于您的类中,您不应该声明它。

    你应该使用 org.apache.openejb.core.LocalInitialContextFactory 如果你遵循这个例子。您的类路径中没有该类,因为我想您还没有添加它。添加每个所需的库可能既长又复杂。 你应该使用pom。示例中提出的xml。

    如果可以,我可以提供一些建议:
    安装Maven,学习使用它的基础,从头签出项目,然后用Maven构建: http://svn.apache.org/repos/asf/tomee/tomee/trunk/examples/simple-stateless-with-descriptor/