0% found this document useful (0 votes)
101 views70 pages

301 - Step by Step: Making Enterprise Javabeans With J2Ee Standard Tools

The document provides an overview and agenda for a presentation on developing Enterprise JavaBeans (EJBs) using J2EE standard tools. It discusses EJB types and files, challenges with EJB 2.x, and how EJB 3.0 and Java EE 5 address these issues. It also outlines the Web Tools Platform (WTP), J2EE Standard Tools (JST), and steps for creating an EJB project including entity beans, session beans, and a session bean client.

Uploaded by

jayabharat
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views70 pages

301 - Step by Step: Making Enterprise Javabeans With J2Ee Standard Tools

The document provides an overview and agenda for a presentation on developing Enterprise JavaBeans (EJBs) using J2EE standard tools. It discusses EJB types and files, challenges with EJB 2.x, and how EJB 3.0 and Java EE 5 address these issues. It also outlines the Web Tools Platform (WTP), J2EE Standard Tools (JST), and steps for creating an EJB project including entity beans, session beans, and a session bean client.

Uploaded by

jayabharat
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 70

301 - Step by Step: Making Enterprise JavaBeans With J2EE Standard Tools Christopher M.

Judd
President/Consultant Judd Solutions, LLC

Christopher M. Judd President/Consultant of Judd Solutions Leader Creator Open Source projects FallME and Fiddle

Agenda
EJB Overview WTP Overview JST Overview Workspace Setup EJB Development
Entity Bean Session Bean Session Bean Client

Deploy Packaging Debugging Conclusion

Enterprise JavaBean Development was HARD!!!

EJB Types Session Server-side business logic


Stateful Stateless

Entity Persistable business objects


CMP BMP

Message-Driven Consumers of JMS messages

EJB 2.x Files Session


Remote Interface Home Interface Local Interface Local Home Interface Bean Class EJB Deployment Descriptor App Server Specific EJB Deployment Descriptor

EJB 2.x Files Entity


Remote Interface Home Interface Local Interface Local Home Interface Bean Class EJB Deployment Descriptor App Server Specific EJB Deployment Descriptor App Server Specific CMP Deployment Descriptor

EJB 2.x Files Message-Driven Bean


Bean Class EJB Deployment Descriptor App Server Specific EJB Deployment Descriptor

Managing Complexity
Hand code classes, interfaces deployment descriptors Diagrams

Doclet Annotations

/** * A generated session bean * @ejb.bean name="TransService" * description="A session bean named TransService" * display-name="TransService" * jndi-name="TransService" * type="Stateless" * transaction-type="Container" */ public abstract class TransServiceBean implements javax.ejb.SessionBean {

Java 5 Annotations

EJB 2.x Problems Too much work Too much to know Too much XML Too many patterns
DTO Locator Service

Difficult to test Breaks object oriented principals

EJB 3.0 Solution Plain Old Java Objects (POJO) Annotations over XML Java Persistence API (JPA) Dependency Injection Fewer files

Agenda
EJB Overview WTP Overview JST Overview Workspace Setup EJB Development
Entity Bean Session Bean Session Bean Client

Deploy Packaging Debugging Conclusion

Web Tools Platform Project (WTP)


Top Level Eclipse Project www.eclipse.org/webtools/ Included in Ganymede and Europa release Current version 3.0.2 Development tools for web and Java EE development
No runtime dependencies Vendor extensible

Dependencies
Java 5 SDK or higher Eclipse 3.4.1 EMF 2.4.1 GEF 3.4.1 DTP 1.6.1

WTP Subprojects Web Standard Tools (WST)


Web artifacts Defined by open standards bodies

J2EE Standard Tools (JST)


Java EE and J2EE components Java Community Process (JCP) Depends on WST

Dali
EJB 3.0 Java Persistance API (JPA) support

JavaServer Faces Tools (JSF) AJAX Toolkit Framework (ATF)

WTP Scope

WTP Installation Options Ganymede All-in-one


Eclipse 3.4.1 Eclipse Modeling Framework (EMF) 2.4.1 Graphic Editor Framework (GEF) 3.4.1 Data Tools Platform (DTP) 1.6.1

Update Manager
Eclipse.org update site

Piecemeal
* ATF is a separate install

Agenda
EJB Overview WTP Overview JST Overview Workspace Setup EJB Development
Entity Bean Session Bean Session Bean Client

Deploy Packaging Debugging Conclusion

JST Scope J2EE 1.4 support


EJB 2.1 Servlet 2.4 JSP 2.0 JMS 1.1 JTA 1.0 JavaMail 1.3 JAF 1.0 JAXP 1.2 Connector 1.5 Web Services 1.1 JAX-RPC 1.1 SAAJ 1.2 JAXR 1.0 J2EE Management 1.0 JMX 1.2 J2EE Deployment 1.1 JACC 1.0

JST Scope Java EE 5 support


EJB 3.0 JPA JSR-220 Servlet 2.5 JSP 2.1 JSF 1.2 JMS 1.1 JTA 1.1 JavaMail 1.4.1 JAF 1.1 Connector 1.5 Common Annotations JAX-WS 2.0 JAX-RPC 1.1 JAXB 2.0 SAAJ 1.1.2 SAAJ 1.2 J2EE Management J2EE Deployment JACC

JST Projects Projects Types


Enterprise Application Project (ear) EJB Project (ejb-jar) Dynamic Web Project (war) Application Client Project (jar) Connector Project (rar)

JST Projects
Project Layouts
Project per module
Enterprise Application Project (ear)

Application Client Project (jar) EJB Project (ejb-jar)

Dynamic Web Project (war)

J2EE Perspective

JPA Perspective

Agenda
EJB Overview WTP Overview JST Overview Workspace Setup EJB Development
Entity Bean Session Bean Session Bean Client

Deploy Packaging Debugging Conclusion

Infrastructure

Configure workspace
Application server Data source

Workspace Setup Configure application server runtime

Supported Servers
Apache Tomcat
3.2 4.1 5.5 - 4.0 - 5.0 - 6.0

Apache Geronimo 1.0 IBM WebSphere 6.0.x JBoss 3.2.x, 4.2, 4.0, 5.0 JOnAS 4.x Oracle OC4J Standalone 10.1.3

Download Additional Server Adapters Pramati Server Apache Geronimo GlassFish Jetty IBM WebSphere Application Server Community Edition IBM WebSphere Oracle WebLogic

Defining Server 1. 2. 3. 4. Configure server appropriate JDK Configure server runtime Configure server Test server

Configure JDK
Window > Preferences > Java > Installed JREs

Note: You may have to add tools.jar for JSP support

Configure Server Runtime


Window > Preferences > Server > Installed Runtimes

Configure Server Use Server View in J2EE Perspective 1. Add server (New > Server)

Test Server 1. Start server

2. Verify server is up

Server View Usability Tip


Move Server View above Console view
Easier application server startup Easier deployment

Agenda
EJB Overview WTP Overview JST Overview Workspace Setup EJB Development
Entity Bean Session Bean Session Bean Client

Deploy Packaging Debugging Conclusion

Application Design

Example will be developed from right to left Entity Bean > Session Bean > Servlet

Create Enterprise Application Project


New > Project > J2EE > Enterprise Application Project Add EJB and Web modules Select Application Server

Projects Ticket > EAR TicketEJB > EJB TicketWeb > WAR

Agenda
EJB Overview WTP Overview JST Overview Workspace Setup EJB Development
Entity Bean Session Bean Session Bean Client

Deploy Packaging Debugging Conclusion

Create Entity Bean Process 1. Enable JPA on EJB project


Configure database connection Configure driver definition

2. Generate Entity Bean 3. Configure application server data source 4. Configure JNDI in application

Enable JPA on EJB project Enable Java Persistence 1.0


EJB Project Properties > Project Facets

Configure JPA
EJB Project Properties > JPA

Configure Database Connection Add Connection on Java Persistence Facet Optionally add via the Data Source Explorer

Configure Driver Definition


Optionally added via Window > Preferences > Connectivity > Driver Definitions

Generate Entity Bean Generate from existing tables in database Right-click on EJB project > JPA Tools > Generate Entities

Entity Bean Source


@Entity public class Ticket implements Serializable { @Id private long id; private Timestamp submitted; private String detail; private String summary; public Ticket() { super(); } public long getId() { return this.id; } public void setId(long id) { this.id = id; } public Timestamp getSubmitted() { return this.submitted; } public void setSubmitted(Timestamp submitted) { this.submitted = submitted; } public String getDetail() { return this.detail; } public void setDetail(String detail) { this.detail = detail; } public String getSummary() { return this.summary; } public void setSummary(String summary) { this.summary = summary; } }

Entity Bean Support Content Assist (Ctrl + Space) for Annotations JPA Details view

Configure App Server Data Source Application server and database specific

Configure JNDI in Application ejbModule\META-INF\persistence.xml


Add transaction type Add JTA data source

<?xml version="1.0" encoding="UTF-8"?> <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"> <persistence-unit name="TicketEJB" transaction-type="JTA"> <jta-data-source>jdbc/TicketDataSource</jta-data-source> <class>com.juddsolutions.entities.Ticket</class> </persistence-unit> </persistence>

Agenda
EJB Overview WTP Overview JST Overview Workspace Setup EJB Development
Entity Bean Session Bean Session Bean Client

Deploy Packaging Debugging Conclusion

Create Session Bean Process 1. Create Session Interface 2. Create Session Class
Inject EntityManager Implement Session Bean

Create Session Interface Standard Java Interface Optional Local or Remote defaults to Local

public interface TicketService { Ticket findTicketById(Long id); }

Create Session Class


Standard Java Class Stateful or Stateless annotation Inject EntityManager and/or other Session Beans
@Stateless public class TicketServiceImpl implements TicketService { @PersistenceContext EntityManager entityManager; public Ticket findTicketById(Long id) { return entityManager.find(Ticket.class, id); } }

Agenda
EJB Overview WTP Overview JST Overview Workspace Setup EJB Development
Entity Bean Session Bean Session Bean Client

Deploy Packaging Debugging Conclusion

Create Session Bean Client 1. 2. 3. 4. Create Client (Servlet) Enable EJB J2EE Module Inject Session Bean Call Session Bean

Create Client Class Standard Servlet New > Web > Servlet

Enable EJB J2EE Module


Access EJB classes Web Project Properties > J2EE Module Dependencies

Client Source
public class TicketServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet { private static final String BR = "<br>"; @EJB private TicketService service; protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter writer = response.getWriter(); String id = request.getParameter("id"); Ticket ticket = service.findTicketById(Long.valueOf(id)); writer.println("Id: " + ticket.getId() + BR); writer.println("Summary: " + ticket.getSummary() + BR); writer.println("Detail: " + ticket.getDetail() + BR); } }

Agenda
EJB Overview WTP Overview JST Overview Workspace Setup EJB Development
Entity Bean Session Bean Session Bean Client

Deploy Packaging Debugging Conclusion

Deploy Right click on server and Add and Remove Projects

Test
http://localhost:8080/TicketWeb/TicketServlet

Agenda
EJB Overview WTP Overview JST Overview Workspace Setup EJB Development
Entity Bean Session Bean Session Bean Client

Deploy Packaging Debugging Conclusion

Packaging Export > J2EE > EAR file Deploy to standard Java EE App Server

Agenda
EJB Overview WTP Overview JST Overview Workspace Setup EJB Development
Entity Bean Session Bean Session Bean Client

Deploy Packaging Debugging Conclusion

Debugging
Just start server in debug mode and debug like standard Java application

Agenda
EJB Overview WTP Overview JST Overview Workspace Setup EJB Development
Entity Bean Session Bean Session Bean Client

Deploy Packaging Debugging Conclusion

Conclusion JST includes all the tools necessary for developing, deploying and testing EJB 3.0 and EJB 2.1 applications.

WTP Resources
www.eclipse.org/webtools/ www.projst.com Tutorials
http://www.eclipse.org/webtools/community/communityr esources.html#tutorials Building an JEE5 Application using EJB3 Session and JPA Entities

Articles
http://www.eclipse.org/webtools/community/communityr esources.html#articles

New Group
news://news.eclipse.org/eclipse.webtools

Dali
http://www.eclipse.org/dali/

J2EE Resources www.javasoft.com www.theserverside.com Java EE 5 Specification


http://jcp.org/aboutJava/communityprocess/fin al/jsr244/index.html http://java.sun.com/javaee/5/docs/api/

J2EE 1.4 Specification


java.sun.com/j2ee/j2ee-1_4-fr-spec.pdf java.sun.com/j2ee/1.4/docs/api/

EJB 3.0 & EJB 2.1 Specification


http://java.sun.com/products/ejb/docs.html

Contact Information
Website: http://www.juddsolutions.com Email: [email protected] Blog: http://juddsolutions.blogspot.com/ Beginning Groovy and Grails
http://www.apress.com/book/view/1430210451

Pro Eclipse JST


http://www.apress.com/book/bookDisplay.html?bID=447

Enterprise Java Development on a Budget


http://www.apress.com/book/bookDisplay.html?bID=197

Questions ?
Please fill out your evaluations. Slides can be found at http://www.juddsolutions.com/ew2008/

You might also like