Building Geronimo 1.1 GBeans with Maven 2.0
You can download the source code archive from my site. First let’s look at what you will find in the archive.
GeronimoHelloWorldGBean/pom.xml GeronimoHelloWorldGBean/src/main/java/com/sateh/geronimo/plugins/helloworld/HelloWorldGBean.java GeronimoHelloWorldGBean/src/main/resources/META-INF/geronimo-service.xml
As you can see this is a pretty standard Maven 2.0 project. The pom.xml describes the project, the HelloWorldGBean.java implements the actual GBean and the geronimo-service.xml contains the deployment plan for the GBean.
The deployment plan is embedded in the GBean’s jar file, which will look like this:
com/sateh/geronimo/plugins/helloworld/HelloWorldGBean.class META-INF/geronimo-service.xml
The Maven project descriptor for this GBean is very simple:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.sateh.geronimo.plugins</groupId>
<artifactId>helloworld</artifactId>
<version>1.0</version>
<name>Geronimo Hello World GBean</name>
<dependencies>
<dependency>
<groupId>org.apache.geronimo.modules</groupId>
<artifactId>geronimo-kernel</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.0.4</version>
</dependency>
</dependencies>
</project>
There is no Geronimo specific packaging needed because deployable items like a GBean are simply packaged as jar files. This is nice since it doesn’t require any special Maven plugins or project structure.
This project only depends on the Geronimo Kernel module and Commons Logging. When I wrote this blog entry the Geronimo 1.1 modules were not yet added to the main Maven 2.0 repository so I had to manually add them to the local Maven artifact repository. This is not a big deal, you can simply do this by using the following command:
% cd geronimo-1.1 % mvn install:install-file -DgroupId=org.apache.geronimo.modules -DartifactId=geronimo-kernel -Dversion=1.1 -Dpackaging=jar -DgeneratePom -Dfile=/repository/geronimo/geronimo-kernel/1.1/geronimo-kernel-1.1.jar
The GBean’s implementation looks like this:
public class HelloWorldGBean implements GBeanLifecycle
{
private final static Log sLog = LogFactory.getLog(HelloWorldGBean.class);
public void doStart() throws Exception
{
sLog.info("doStart");
}
public void doStop() throws Exception
{
sLog.info("doStop");
}
public void doFail()
{
sLog.info("doFail");
}
public static final GBeanInfo GBEAN_INFO;
static {
GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic("HelloWorldGBean", HelloWorldGBean.class);
GBEAN_INFO = infoBuilder.getBeanInfo();
}
public static GBeanInfo getGBeanInfo()
{
return GBEAN_INFO;
}
}
More information about writing GBeans can be found online. Check out the articles on DeveloperWorks or the Geronimo web site for links to books and more articles.
The deployment plan looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="http://geronimo.apache.org/xml/ns/deployment-1.1">
<environment>
<moduleId>
<groupId>com.sateh.geronimo.plugins
<artifactId>helloworld
<version>1.0
<type>car
</moduleId>
</environment>
<gbean name=”HelloWorld” class=”com.sateh.geronimo.plugins.helloworld.HelloWorldGBean”>
</gbean>
</module>
Again, pretty minimal to keep the example simple.
Building and deploying the bean is done like this:
% cd GeronimoHelloWorldGBean
% mvn package
% java -jar $GERONIMO_HOME/bin/deployer.jar --user system --password manager
deploy target/helloworld-1.0.jar
And you should see something like this in the Geronimo log file:
12:22:54,978 INFO [HelloWorldGBean] doStart
(I usually start Geronimo with the -v option so that it logs INFO and DEBUG entries to stdout)
You can confirm that the module is loaded by asking the deployer tool to list all modules:
% java -jar $GERONIMO_HOME/bin/deployer.jar --user system --password manager list-modules
Found 15 modules
+ com.sateh.geronimo.plugins/helloworld/1.0/car
+ geronimo/geronimo-gbean-deployer/1.1/car
+ geronimo/j2ee-deployer/1.1/car
+ geronimo/j2ee-security/1.1/car
+ geronimo/j2ee-server/1.1/car
+ geronimo/j2ee-system/1.1/car
+ geronimo/jetty/1.1/car
+ geronimo/jetty-deployer/1.1/car
+ geronimo/rmi-naming/1.1/car
+ geronimo/sharedlib/1.1/car
+ geronimo/unavailable-client-deployer/1.1/car
+ geronimo/unavailable-ejb-deployer/1.1/car
+ geronimo/unavailable-webservices-deployer/1.1/car
geronimo/online-deployer/1.1/car
geronimo/shutdown/1.1/car
That’s it! You have just developed and deployed your first GBean in Geronimo 1.0.
Created
