javaglassfishapplication-client

GlassFish Application Client Container


I'm trying to work with the Embeddable Glassfish app client container. The only resources I can find are the above mentioned javadocs which contain this tantalising code snippet

import org.glassfish.appclient.client.acc.AppClientContainer;
import org.glassfish.appclient.client.acc.config.TargetServer;

AppClientContainerBuilder builder = AppClientContainer.newBuilder(
   new TargetServer("localhost", 3700));

AppClientContainer acc = builder.newContainer(new File("myAC.jar").toURI());

(or, alternatively)

AppClientContainer acc = builder.newContainer(MyClient.class);

then,

acc.startClient(clientArgs);
// The newContainer method returns as soon as the client's main method returns,
// even if the client has started another thread or is using the AWT event
// dispatcher thread 
// At some later point, the program can synchronize with the app client in
// a user-specified way at which point it could invoke

acc.stop();

This looks pretty awesome, but I've tried to get this to run a couple of times with various different errors.

Has anybody got any experience using this, or could they point me in the direction of some resources that explain how to work with this?


Solution

  • I have this working with Glassfish 3.1.2 and a simple Java Swing UI application. The host/port specified by TargetServer appears to be ignored, I had to set the system properties:

    org.omg.CORBA.ORBInitialHost = hostname
    org.omg.CORBA.ORBInitialPort = 2037
    

    to get a connection as I am not running on the default ports.

    To get it all to compile, it would help if Oracle documented that AppClientContainer etc. are in package:

    org.glassfish.appclient.client.acc
    

    then you can find which .jars are needed for compilation, which were:

    gf-client,jar, gf-client-module.jar, acc-config.jar
    

    The AppClientContainer.startClient attempts to invokes a method:

    public static void main(String[] args)
    

    on MyClient.class, which might not be exactly what you want; In my case my goal is to make this work with an Eclipse-based application, which would also like to "own" the launch. In addition the OSGI environment I need seems to be completely at odds with the Glassfish ACC, having its own incompatible classloading mechanism.

    Although it's needed for the startClient call, the main method doesn't seem to get called in a separate Thread or anything special. I found I can simply supply a dummy main which does nothing and have all my application code straight after the startClient call returns.

    This whole ACC implementation seems to be the only supported way of connecting a standalone client to an application running on Glassfish 3. It is rather unsatisfactory compared to the simplicity available with v2. The huge list of .jars includes all sorts of things that are of no interest to me at all, indeed at startup I see this message:

    15-May-2012 17:49:27 com.sun.enterprise.v3.server.CommonClassLoaderServiceImpl findDerbyClient
    INFO: Cannot find javadb client jar file, derby jdbc driver will not be available by default.
    

    Also Oracle have dumped an SLF4J logger implementation in bean-validator.jar which is colliding with my own preferred implementation, causing a further error message.

    The Glassfish EJB FAQ at http://glassfish.java.net/javaee5/ejb/EJB_FAQ.html has been updated for v3 and is also of some help.