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">
<environment>
<moduleId>
<groupId>com.example.gbeans</groupId>
<artifactId>TestGBean</artifactId>
<version>1.1</version>
</moduleId>
</environment>
<gbean name="TestGBean" class="com.example.TestGBean">
<attribute name="message">buenos dias</attribute>
</gbean>
</module>
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 0.0.0.0 RMI Naming
1527 0.0.0.0 Derby Connector
4201 0.0.0.0 ActiveIO Connector EJB
4242 0.0.0.0 Remote Login Listener
8080 0.0.0.0 Jetty Connector HTTP
8443 0.0.0.0 Jetty Connector HTTPS
9999 0.0.0.0 JMX Remoting Connector
61613 0.0.0.0 ActiveMQ Transport Connector
61616 0.0.0.0 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/
2.0-M1/car
WAR: org.apache.geronimo.configs/welcome-jetty/2.0-M1/car
Web Applications:
http://localhost:8080/
http://localhost:8080/console
http://localhost:8080/console-standard
http://localhost:8080/dojo
http://localhost:8080/remote-deploy
At this point, you're ready to deploy your GBean to Geronimo.