Search code examples
javaubuntuglassfish

Glassfish5 Error: Exception in thread "main" java.lang.NullPointerException


I have installed glassfish 5 in ubuntu and put it under the directory /opt, but when I typed asadmin start-domain I face this error:

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "org.glassfish.hk2.api.DynamicConfigurationService.createDynamicConfiguration()" because "dcs" is null
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 com.sun.enterprise.admin.cli.CLIContainer.getServiceLocator(CLIContainer.java:217)   
at com.sun.enterprise.admin.cli.CLIContainer.getLocalCommand(CLIContainer.java:255)     
at com.sun.enterprise.admin.cli.CLICommand.getCommand(CLICommand.java:231)  
at com.sun.enterprise.admin.cli.AdminMain.executeCommand(AdminMain.java:371)    
at com.sun.enterprise.admin.cli.AdminMain.doMain(AdminMain.java:306)    
at org.glassfish.admin.cli.AsadminMain.main(AsadminMain.java:57)

How can I solve this problem?


Solution

  • Glassfish version 5 shows that behaviour when run with openjdk15 (at least in my machine) I have configured (see below) it to run with JDK-8 and it starts correctly.

    set JAVA_HOME="Your_path_to_jdk8"
    set PATH="%JAVA_HOME%/bin;%PATH%"
    

    in windows, or

    export JAVA_HOME="Your_path_to_jdk8"
    export PATH="${JAVA_HOME}/bin:${PATH}"
    

    in unix/linux. Add this to the script you use to start it, so the environment directs Glassfish to the proper place to find java binaries.