Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This is an example of a JSP-page calling a Session Bean. The result looks like this:
I have tried to strip of everything just to make this example as easy as possible to understand. This is an example using Geronimo 2.0, Java 1.5 and EJB 3.0.

...

Code Block
java
java
borderStylesolid
titleMyTimeBean.java
package org.apache.geronimo.samples.mytimepak;

import javax.ejb.Stateless;

@Stateless
public class MyTimeBean implements MyTimeLocal {

	public String getTime() {
		String s = new java.util.Date().toString();
		return s;
	}   	
}

MyTimeLocal.java is the Local interface. As this EJB will only be used from a JSP-page that is running in the same server (same JVM) I use a Local interface that do not make use of the network.

...

Code Block
xml
xml
borderStylesolid
titleopenejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<openejb-jar
		xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1"
		xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.1" 
		xmlns:pkgen="http://www.openejb.org/xml/ns/pkgen-2.0" 
		xmlns:sec="http://geronimo.apache.org/xml/ns/security-1.1" 
		xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2">
  <sys:environment>
    <sys:moduleId>
      <sys:groupId>org.apache.geronimo.samples<groupId>${pom.groupId}</sys:groupId>
      <sys:artifactId>inventory<artifactId>${pom.artifactId}</sys:artifactId>
      <sys:version>1.0<version>${version}</sys:version>
      <sys:type>car<type>jar</sys:type>
    </sys:moduleId>
  </sys:environment>
</openejb-jar>

...

Code Block
xml
xml
borderStylesolid
titlegeronimo-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.1" 
         xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.1" 
         xmlns:sec="http://geronimo.apache.org/xml/ns/security-1.1" 
         xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.1">
  <sys:environment>
    <sys:moduleId>
      <sys:groupId>org.apache.geronimo.samples<groupId>${pom.groupId}</sys:groupId>
      <sys:artifactId>MyTimeWeb<artifactId>${pom.artifactId}</sys:artifactId>
      <sys:version>1.0<version>${version}</sys:version>
      <sys:type>car<type>war</sys:type>
    </sys:moduleId>
  </sys:environment>
  <context-root>/mytime</context-root>
</web-app>

...

Code Block
xml
xml
borderStylesolid
titleweb.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" 
    xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
	<display-name>MyTimeWeb</display-name>
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
	<!-- To refer local EJB's  -->
	<ejb-local-ref>
		<ejb-ref-name>ejb/MyTimeBean</ejb-ref-name>
		<ejb-ref-type>Session</ejb-ref-type>
		<local>org.apache.geronimo.samples.mytimepak.MyTimeLocal</local>
	</ejb-local-ref>
</web-app>

...

You can checkout the source code of this sample from SVN:

svn checkout http://svn.apache.org/repos/asf/geronimo/samples/trunk/samples/mytimeImage Removed

Building

Use a command prompt to navigate into the mytime directory and just give mvn clean install site command to build. It will create the mytime-ear-2.0-SNAPSHOT.ear under the mytime folder. Now, you are ready to deploy mytime application in the Geronimo Application server.

...

To test the sample web application open a browser and type http://localhost:8080/mytimeImage Removed.