RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Exploring Geronimo's GBean Framework : Page 3

Apache Geronimo is a general runtime execution environment and certified J2EE application server that you can configure to satisfy many different infrastructure requirements.

An Example GBean
A GBean is a simple Java class that is extended to implement the org.apache.geronimo.gbean.GBeanLifecycle interface and to define attributes, references, and operations via a public static method with the signature, GBeanInfo getGBeanInfo. A GBean should, by convention, also create an instance of GBeanInfo in a static initializer block and expose this instance as a public static final field called GBEAN_INFO.

According to these rules, a very simple GBean would look similar to the class shown in Listing 1.

Integrating a GBean into Geronimo
With the GBean class defined, you must compile and encapsulate it within an archive file (.ear, .war, .jar, etc.). The archive must contain the deployment plan for the GBean, and that plan must conform one of the deployment schemas found in the /schema directory. This example deploys the TestGBean as a standalone module; therefore it must conform to the geronimo-module-1.x.xsd schema.

Here's a simple standalone module plan for the TestGBean shown in Listing 1:

   <?xml version="1.0" encoding="UTF-8"?>
   <module xmlns="http://geronimo.apache.org/xml/ns/deployment-1.1">
      <gbean name="TestGBean" class="com.example.TestGBean">
         <attribute name="message">buenos dias</attribute>
Now that the plan is in place, use the jar command-line tool to create a jar file for TestGBean, as follows:

   $ jar -Mcvf mygbean.jar com/example/*.class
After creating the .jar file, start the Geronimo server by executing the startup script you'll find in /bin. The Geronimo startup console will appear and when the server is ready, you should see output similar to the following:

   Startup completed in 27 seconds
     Listening on Ports:
       1099 RMI Naming
       1527 Derby Connector
       4201 ActiveIO Connector EJB
       4242 Remote Login Listener
       8080 Jetty Connector HTTP
       8443 Jetty Connector HTTPS
       9999 JMX Remoting Connector
      61613 ActiveMQ Transport Connector
      61616 ActiveMQ Transport Connector
     Started Application Modules:
       EAR: org.apache.geronimo.configs/webconsole-jetty6/2.0-M1/car
       RAR: org.apache.geronimo.configs/activemq/2.0-M1/car
       RAR: org.apache.geronimo.configs/system-database/2.0-M1/car
       WAR: org.apache.geronimo.configs/dojo-jetty6/2.0-M1/car
       WAR: org.apache.geronimo.configs/remote-deploy-jetty/
       WAR: org.apache.geronimo.configs/welcome-jetty/2.0-M1/car
     Web Applications:
At this point, you're ready to deploy your GBean to Geronimo.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date