Search code examples
javajakarta-eeglassfishejbinitial-context

javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.SerialInitContextFactory


I'm deploying an application making use of EJB. I'have wrote an EJB and a java standalone client to connect to. Everything works correctly in Netbeans, but when i try to start in command line I got exceptions. The JavaFX Application contains the following code :

    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);
    }

I have tried the following :

java -jar CDM.jar

And the error I get is :

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

I really don't know how to fix it.

Many thanks for your help in advance !


Solution

  • EDIT :

    When I use the following it works

    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