-
1. Re: where is the samples?
jasonbrome Aug 17, 2002 8:09 PM (in response to laha)Have you checked out the JBoss 3.0 Getting Started docs, and the accompanying examples?
http://www.jboss.org/docs/#free-30x -
2. Re: where is the samples?
bakul Aug 23, 2002 3:45 PM (in response to laha)I checked the Quickstart guide. There is nothing on EJBs. There were no examples either. Thers is mention of a template project. Other than that I couldn't find any samples/examples of any sort? Any idea on where I can find some?
Thanks
Bakul -
3. Re: where is the samples?
torreblanca Aug 28, 2002 2:44 PM (in response to laha)Bakul,
I followed the "Mastering Enterprise JavaBeans" (Ed Roman) book examples. The examples are working in JBoss-3.0.1_Tomcat-4.0.4. I only changed the xml configuration files. The EAR, WAR and JAR structure file is very important to deploy applications.
You can get free this e-book at :
http://www.theserverside.com/books/masteringEJB/index.jsp
In this reply I explain a Session Stateless Session bean and in other replies I will send you examples of Stateful Session bean, Bean-Managed Persistent Entity Bean, Container-Managed Persistent Entity Bean and Message-driven bean.
I need to prepare every document, let me a little time.
________________________________________
Stateless Session Bean
This Stateless Session bean example shows the date.
1. Create the following files : PrimerEJB.java, PrimerHome.java and Primer.java at
[drive]:\examples\src
Source of PrimerEJB.java
__________________________________________________
package com.ejb1;
import javax.ejb.SessionBean;
import javax.ejb.EJBException;
import javax.ejb.SessionContext;
import java.rmi.RemoteException;
import java.util.Date;
public class PrimerEJB implements SessionBean {
public String recuperaTiempo() {
return "La fecha es : " + new Date().toString();
}
public void ejbCreate() {}
public void ejbPassivate() {}
public void ejbActivate() {}
public void ejbRemove() {}
public void setSessionContext(SessionContext context) {}
}
_________________________________________________
The recuperaTiempo method retrieves the date.
Source of PrimerHome.java
________________________________________________
package com.ejb1;
import javax.ejb.EJBHome;
import javax.ejb.CreateException;
import java.rmi.RemoteException;
import com.ejb1.Primer;
public interface PrimerHome extends EJBHome {
public Primer create() throws CreateException, RemoteException;
}
________________________________________________
Source of Primer.java
________________________________________________
package com.ejb1;
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
public interface Primer extends EJBObject {
public String recuperaTiempo() throws RemoteException;
}
________________________________________________
2. Compile PrimerEJB.java, PrimerHome.java and Primer.java in [drive]:\examples\src.
javac -d d:\examples\src -classpath %classpath%;.;d:\examples\src;d:\jboss-3.0.1_Tomcat-4.0.4\client\jboss-j2ee.jar *.java
3. The before step creates the following directory structure:
[drive]:\examples\src\com\ejb1\PrimerEJB.class
[drive]:\examples\src\com\ejb1\PrimerHome.class
[drive]:\examples\src\com\ejb1\Primer.class
4. Create the jsp (primerEJB.jsp)
Source of primerEJB.jsp
____________________________________________________________
<%@ page import="javax.naming.InitialContext,
javax.naming.Context,
java.util.Properties,
com.ejb1.Primer,
com.ejb1.PrimerHome"%>
<%
long t1 = System.currentTimeMillis();
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
props.put(Context.PROVIDER_URL, "13.134.79.127:1099");
Context ctx = new InitialContext(props);
PrimerHome home = (PrimerHome)ctx.lookup("ejb/Primer");
Primer bean = home.create();
String time = bean.recuperaTiempo();
bean.remove();
ctx.close();
long t2 = System.currentTimeMillis();
%>
p { font-family:Verdana;font-size:12px; }
Mensaje recibido del bean = "<%= time %>".Tiempo transcurrido :
<%= (t2 - t1) %> ms.
_________________________________________________________
You need to change the following line:
props.put(Context.PROVIDER_URL, "13.134.79.127:1099");
change to your IP ADDRESS JBOSS_TOMCAT SERVER :
props.put(Context.PROVIDER_URL, "[IP ADDRESS SERVER]:1099");
5. Create ejb-jar.xml in [drive]:\examples\src\META-INF
Source of ejb-jar.xml
_______________________________________________________
<?xml version="1.0"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems,
Inc.//DTD Enterprise JavaBeans 2.0//EN"
"http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<enterprise-beans>
<display-name>PrimerEJB</display-name>
<ejb-name>Primer</ejb-name>
com.ejb1.PrimerHome
com.ejb1.Primer
<ejb-class>com.ejb1.PrimerEJB</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Bean</transaction-type>
</enterprise-beans>
</ejb-jar>
________________________________________________________
6. Create jboss.xml in [drive]:\examples\src\META-INF
Source of jboss.xml
_______________________________________________________
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS//EN"
"http://www.jboss.org/j2ee/dtd/jboss.dtd">
<enterprise-beans>
<ejb-name>Primer</ejb-name>
<jndi-name>ejb/Primer</jndi-name>
</enterprise-beans>
_______________________________________________________
The value in <jndi-name> tag is equal to the following line used in primerEJB.jsp :
PrimerHome home = (PrimerHome)ctx.lookup("ejb/Primer");
7. Create [drive]:\examples\src\WEB-INF\classes and then copy the EJB classes with their package structure (PrimerEJB.class, PrimerHome.class and Primer.class).
the result is :
[drive]:\examples\src\WEB-INF\classes\com\ejb1\PrimerEJB.class
[drive]:\examples\src\WEB-INF\classes\com\ejb1\PrimerHome.class
[drive]:\examples\src\WEB-INF\classes\com\ejb1\Primer.class
8. Create the JAR file (primerEJB.jar). Change to [drive]:\examples\src directory and use the following instruction :
jar -cvfM primerEJB.jar com META-INF
9. Create the WAR file (primerEJB.war). Change to [drive]:\examples\src directory and use the following instruction :
jar -cvfM primerEJB.war WEB-INF primerEJB.jsp
10. Copy the JAR file (primerEJB.jar) and WAR file (primerEJB.war) to [drive]:\examples
11. Create application.xml in [drive]:\examples\META-INF directory.
Source of application.xml
__________________________________________________________
<?xml version="1.0" encoding="ISO-8859-1"?>
<display-name>Primer EJB</display-name>
<web-uri>primerEJB.war</web-uri>
<context-root>/primerEJB</context-root>
primerEJB.jar
__________________________________________________________
The value in <web-uri> tag is the name of your WAR file.
The value in <context-root> tag is the context of your application.
The value in tag is the name of your JAR file.
12. Create the EAR file (primerEJB.ear). Change to [drive]:\examples directory and use the following instruction :
jar -cvfM primerEJB.ear primerEJB.jar primerEJB.war META-INF
13. Copy the EAR file to %JBOSS_HOME%\server\default\deploy.
14. Run JBoss-Tomcat Server
15. Test the application :
http://[IP ADDRESS JBOSS-TOMCAT SERVER]:8080/primerEJB/primerEJB.jsp
You can automate this building process using Ant.
In the next reply I will send you in attachment the EAR file (primerEJB.ear)
Regards
Javier -
4. Re: where is the samples?
torreblanca Aug 28, 2002 2:46 PM (in response to laha)Here is the attachment. PrimerEJB.ear
Regards
Javier -
5. Re: where is the samples?
torreblanca Aug 28, 2002 3:47 PM (in response to laha)Bakul,
In this moment I found in the forum a Monson-Haefel book using EJB with JBoss, the address is :
http://www.monson-haefel.com/titanbooks/download.html
Regards
Javier -
6. Re: where is the samples?
reneticus Aug 30, 2002 3:47 AM (in response to laha)Torreblanca,
I've been following your nice sample in how to create and deploy a sample servlet and JSP. And I made it to work, thanks so much!
However, I deployed your PrimerEJB.ear sample and it deployed without errors, but when I ran it, it errored-out operation timeout exception. Something like "Failed to connect to 13.134.79.127:1099". I'm using the Jboss-Jetty bundle. Any idea what this error means?
TIA,
Ruy -
7. Re: where is the samples?
torreblanca Aug 30, 2002 11:50 AM (in response to laha)Ruy,
I´m sorry. I did a mistake with attachment PrimerEJB.ear file, because it doesn´t work. I create this EAR with my IP ADDRESS SERVER (13.134.79.127).
You need create a new EAR file with your IP ADDRESS SERVER (Step 4 - Creation of JSP file). You need change in JSP file the following line :
props.put(Context.PROVIDER_URL, "[IP ADDRESS SERVER]:1099");
Regards
Javier