EJB client access with Jakarta EE 9, GlassFish 6.2.3, OpenJDK 17, NetBeans 12.6

Viewed 371

I want to write a simple example where I deploy an EJB with Jakarta EE 9 and JDK 17 on a GlassFish 6.2.3 and access it with an Enterprise Client in JDK 17. I use NetBeans 12.6 to write my code, start/ stop the GlassFish server etc. The TimeClient should simply receive a date as a String from the EJB:

TimeBeanRemote.java:

package com.example;

import jakarta.ejb.Remote;

@Remote
public interface TimeBeanRemote {
    String getTime();
}

TimeBean.java:

package com.example;

import java.text.SimpleDateFormat;
import java.util.Date;
import jakarta.ejb.Stateless;

@Stateless
public class TimeBean implements TimeBeanRemote {
    @Override
    public String getTime() {
        Date d1 = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String formattedDate = df.format(d1);
        return "The time is " + formattedDate;
    }   
}

TimeClient.java:

package timeclient;

import com.example.TimeBeanRemote;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class TimeClient {
    public static void main(String[] args) {
        try {
            InitialContext ctx = new InitialContext();
            Object someEJBObject = ctx.lookup("com.example.TimeBeanRemote");
            TimeBeanRemote timeEJB = (TimeBeanRemote) someEJBObject;
            System.out.println(timeEJB.getTime());
        } catch (NamingException nex) {
            nex.printStackTrace();
        }
    }
}

Deploying the EJB on the GlassFish works fine. But as soon as I try to run the client and access the EJB with it I get the following error:

Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
-Djava.endorsed.dirs=D:\glassfish6\glassfish\lib\endorsed;D:\glassfish6\glassfish\modules\endorsed is not supported. Endorsed standards and standalone APIs
in modular form will be supported via the concept of upgradeable modules.
Java Result: 1

There is a file private.properties located in the TimeClient project in NetBeans in which I find the following entries:

...
j2ee.appclient.tool.jvmoptions=-Djava.endorsed.dirs="D:\\glassfish6\\glassfish\\lib\\endorsed";"D:\\glassfish6\\glassfish\\modules\\endorsed" -javaagent:"D:\\glassfish6\\glassfish\\lib\\gf-client.jar"=mode=acscript,arg=-configxml,arg="D:\\glassfish6\\glassfish\\domains\\glassfish623\\config\\glassfish-acc.xml",client=jar=
j2ee.appclient.tool.jvmoptions.class=-Djava.endorsed.dirs="D:\\glassfish6\\glassfish\\lib\\endorsed";"D:\\glassfish6\\glassfish\\modules\\endorsed" -javaagent:"D:\\glassfish6\\glassfish\\lib\\gf-client.jar"=mode=acscript,arg=-configxml,arg="D:\\glassfish6\\glassfish\\domains\\glassfish623\\config\\glassfish-acc.xml",client=class=
...

And I tried to remove the JVM option parts about -Djava.endorsed, like this:

...
j2ee.appclient.tool.jvmoptions=-javaagent:"D:\\glassfish6\\glassfish\\lib\\gf-client.jar"=mode=acscript,arg=-configxml,arg="D:\\glassfish6\\glassfish\\domains\\glassfish623\\config\\glassfish-acc.xml",client=jar=
j2ee.appclient.tool.jvmoptions.class=-javaagent:"D:\\glassfish6\\glassfish\\lib\\gf-client.jar"=mode=acscript,arg=-configxml,arg="D:\\glassfish6\\glassfish\\domains\\glassfish623\\config\\glassfish-acc.xml",client=class=
...

Which leads to the following error when trying to run the client:

Java HotSpot(TM) 64-Bit Server VM warning: Archived non-system classes are disabled because the java.system.class.loader property is specified (value = "org.glassfish.appclient.client.acc.agent.ACCAgentClassLoader"). To use archived non-system classes, this property must not be set
Error occurred during initialization of VM
java.lang.Error: org.glassfish.appclient.client.acc.agent.ACCAgentClassLoader
    at java.lang.ClassLoader.initSystemClassLoader(java.base@17.0.1/ClassLoader.java:1995)
    at java.lang.System.initPhase3(java.base@17.0.1/System.java:2246)
Caused by: java.lang.ClassNotFoundException: org.glassfish.appclient.client.acc.agent.ACCAgentClassLoader
    at jdk.internal.loader.BuiltinClassLoader.loadClass(java.base@17.0.1/BuiltinClassLoader.java:641)
    at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(java.base@17.0.1/ClassLoaders.java:188)
    at java.lang.ClassLoader.loadClass(java.base@17.0.1/ClassLoader.java:520)
    at java.lang.Class.forName0(java.base@17.0.1/Native Method)
    at java.lang.Class.forName(java.base@17.0.1/Class.java:467)
    at java.lang.ClassLoader.initSystemClassLoader(java.base@17.0.1/ClassLoader.java:1981)
    at java.lang.System.initPhase3(java.base@17.0.1/System.java:2246)

Java Result: 1

Do you have any idea what I am missing here? Thanks in advance

0 Answers
Related