javax.naming.NoInitialContextException:无法实例化类:com.sun.enterprise.naming.SerialInitContextFactory

时间:2018-07-04 09:08:30

标签: java java-ee glassfish ejb initial-context

我正在部署一个使用EJB的应用程序。我已经编写了一个EJB和一个Java独立客户端进行连接。一切在Netbeans中都能正常运行,但是当我尝试在命令行中启动时,出现了异常。 JavaFX应用程序包含以下代码:

    String chemin = IRemoteInterface.class.getName();
    Properties vEnv = new Properties();
    vEnv.put("org.omg.CORBA.ORBInitialHost", "localhost");
    vEnv.put("org.omg.CORBA.ORBInitialPort", "3700");

    try {
        Context ctx = new InitialContext(vEnv);
        leProxy = (IRemoteInterface) ctx.lookup(chemin);
        System.out.println("proxy OK");
    } catch (NamingException ex) {
        System.out.println("erreur proxy");
        Logger.getLogger(CDM.class.getName()).log(Level.SEVERE, null, ex);
    }

我尝试了以下方法:

java -jar CDM.jar

我得到的错误是:

javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.impl.SerialInitContextFactory [Root exception is java.lang.NullPointerException]
    at java.naming/javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
    at java.naming/javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
    at java.naming/javax.naming.InitialContext.init(Unknown Source)
    at java.naming/javax.naming.InitialContext.<init>(Unknown Source)
    at cdm.CDM.main(CDM.java:77)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.base/java.lang.reflect.Method.invoke(Unknown Source)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.base/java.lang.reflect.Method.invoke(Unknown Source)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.NullPointerException
    at com.sun.enterprise.module.common_impl.AbstractModulesRegistryImpl.initializeServiceLocator(AbstractModulesRegistryImpl.java:152)
    at com.sun.enterprise.module.common_impl.AbstractModulesRegistryImpl.newServiceLocator(AbstractModulesRegistryImpl.java:144)
    at com.sun.enterprise.module.common_impl.AbstractModulesRegistryImpl.createServiceLocator(AbstractModulesRegistryImpl.java:218)
    at com.sun.enterprise.module.common_impl.AbstractModulesRegistryImpl.createServiceLocator(AbstractModulesRegistryImpl.java:224)
    at com.sun.enterprise.module.single.StaticModulesRegistry.createServiceLocator(StaticModulesRegistry.java:88)
    at org.glassfish.internal.api.Globals.getStaticHabitat(Globals.java:102)
    at com.sun.enterprise.naming.impl.SerialInitContextFactory.<init>(SerialInitContextFactory.java:130)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.base/java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.base/java.lang.Class.newInstance(Unknown Source)
    ... 16 more

我真的不知道该如何解决。

非常感谢您的提前帮助!

1 个答案:

答案 0 :(得分:0)

编辑:

当我使用以下内容时,它会起作用

java -cp "C:\Program Files\glassfish5\glassfish\lib\appserv-rt.jar;C:\Program Files\glassfish5\glassfish\lib\javaee.jar;C:\Program Files\glassfish5\glassfish\lib\gf-client.jar;CDM.jar" cdm.CDM