Home » Java » netbeans – java.lang.NoSuchMethodError on context lookup-Exceptionshub

netbeans – java.lang.NoSuchMethodError on context lookup-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I’m trying to run ejb client to get information on all the books present in the db.
I’ve deployed the bean with no errors but when i try to run this code:

package book;

import java.util.List;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;


public class BookAllListClient {

    /**
     * @param args the command line arguments
     * @throws javax.naming.NamingException
     */
    public static void main(String[] args) throws NamingException{

        Context ctx = new InitialContext();

        BookEJBRemote book = (BookEJBRemote)ctx.lookup("java:global/Book/BookEJB!book.BookEJBRemote");

        List<Book> books = book.allBook();

        books.forEach((b) -> {
            System.out.println(b);
        });
    }

}

I always get this error

INFO: Cannot find javadb client jar file, derby jdbc driver will not be available by default.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.glassfish.pfl.basic.reflection.Bridge$1 (file:/C:/Users/cirop/GlassFish_Server/glassfish/modules/pfl-basic.jar) to method java.io.ObjectInputStream.latestUserDefinedLoader()
WARNING: Please consider reporting this to the maintainers of org.glassfish.pfl.basic.reflection.Bridge$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Exception in thread "main" java.lang.NoSuchMethodError: sun.misc.Unsafe.defineClass(Ljava/lang/String;[BIILjava/lang/ClassLoader;Ljava/security/ProtectionDomain;)Ljava/lang/Class;
    at org.glassfish.pfl.basic.reflection.BridgeBase.defineClass(BridgeBase.java:237)
    at org.glassfish.pfl.dynamic.codegen.impl.CodeGeneratorUtil.makeClass(CodeGeneratorUtil.java:41)
    at org.glassfish.pfl.dynamic.codegen.spi.Wrapper._generate(Wrapper.java:1023)
    at org.glassfish.pfl.dynamic.codegen.spi.Wrapper._generate(Wrapper.java:1006)
    at com.sun.corba.ee.impl.presentation.rmi.codegen.CodegenProxyCreator.create(CodegenProxyCreator.java:129)
    at com.sun.corba.ee.impl.presentation.rmi.codegen.StubFactoryCodegenImpl.getStubClass(StubFactoryCodegenImpl.java:84)
    at com.sun.corba.ee.impl.presentation.rmi.codegen.StubFactoryCodegenImpl.makeStub(StubFactoryCodegenImpl.java:106)
    at com.sun.corba.ee.impl.util.Utility.loadStub(Utility.java:798)
    at com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:215)
    at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:129)
    at com.sun.enterprise.naming.impl.SerialContext$ProviderCacheKey.getNameService(SerialContext.java:1187)
    at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:369)
    at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:305)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:453)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:414)
    at java.naming/javax.naming.InitialContext.lookup(InitialContext.java:409)
    at bookclientjms.BookClientJMS.main(BookClientJMS.java:33)
C:\Users\cirop\AppData\Local\NetBeans\Cache.2\executor-snippets\run.xml:111: The following error occurred while executing this line:
C:\Users\cirop\AppData\Local\NetBeans\Cache.2\executor-snippets\run.xml:94: Java returned: 1
BUILD FAILED (total time: 12 seconds)

I’m using netbeans IDE and the client has gf-client.jar, javaee web api 7 and javaee api as libraries. What can i do?

How to&Answers: