How to setup JNDI for Glassfish 3.1.2 for a stand-alone client?

后端 未结 3 1812
孤独总比滥情好
孤独总比滥情好 2020-12-04 00:47

I try to connect from a stand-alone swing client (running in a separate JVM on the client machine) to the Glassfish server.

I currently use the following settings fr

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 01:05

    A point to clear about Remote EJB interfaces

    You want a Remote EJB interface when your client application lives on one JVM different than the one hosting the EJB module. In other words:

    • The client application lives on one JVM and the EJB module is deployed on another JVM on the same machine

    OR

    • The client application lives on one JVM and the EJB module is deployed on another JVM on a remote machine.

    For simplicity sake

    Lets consider the first scenario where both of the client app and the EJB module live on different JVMs on the very same machine.

    1. Make sure you have 2 JDKs installed on your machine.
    2. Deploy the EJB module in a Glassfish installation pointing to one JDK (JVM). We can agree to install Glassfish in "C:/glassfish3/"
    3. According to the documantation in this link. Add to your client application classpath the file "gf-client.jar" as an external library from within the installation directory (i.e. C:/glassfish3/glassfish/lib/gf-client.jar) rather than copying it.
    4. Also add to your client application classpath the file remote_interface.jar includes the Remote business interface of your EJB.
    5. Run the SE (stand alone) client application on the second JDK (JVM)

    An important tip about the client

    As per the documentation, stand-alone java clients must explicitly use the global JNDI name to lookup the Remote EJB. Also, Glassfish does not need any properties instialization to invoke the InitialContext() constructor. Thus the client application can invoke the EJB using the following snippet:

    InitialContext context = new InitialContext();
    _RemoteEjbInterface ejbBean = (_RemoteEjbInterface) context.lookup("java:global/DeployedEJBAppName/EjbImplClass!com.sam._RemoteEjbInterface");
    

    In case your SE stand alone client application is a maven one then you need to

    1. Account for the above step (3) by adding this entry to your client app POM:

      
          org.glassfish.main.appclient.client
          gf-client
          3.1.2
          system
          C:/glassfish3/glassfish/lib/gf-client.jar
      
      
    2. Account for the above step (4) by a POM dependency pointing to you remote_interface.jar in your local maven repo assuming you installed it. Follow this to know how.

    Another documentation to reference is here

提交回复
热议问题