301 - Step by Step: Making Enterprise Javabeans With J2Ee Standard Tools
301 - Step by Step: Making Enterprise Javabeans With J2Ee Standard Tools
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
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
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
Dependencies
Java 5 SDK or higher Eclipse 3.4.1 EMF 2.4.1 GEF 3.4.1 DTP 1.6.1
Dali
EJB 3.0 Java Persistance API (JPA) support
WTP Scope
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
JST Projects
Project Layouts
Project per module
Enterprise Application Project (ear)
J2EE Perspective
JPA Perspective
Agenda
EJB Overview WTP Overview JST Overview Workspace Setup EJB Development
Entity Bean Session Bean Session Bean Client
Infrastructure
Configure workspace
Application server Data source
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
Configure Server Use Server View in J2EE Perspective 1. Add server (New > Server)
2. Verify server is up
Agenda
EJB Overview WTP Overview JST Overview Workspace Setup EJB Development
Entity Bean Session Bean Session Bean Client
Application Design
Example will be developed from right to left Entity Bean > Session Bean > Servlet
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
2. Generate Entity Bean 3. Configure application server data source 4. Configure JNDI in application
Configure JPA
EJB Project Properties > JPA
Configure Database Connection Add Connection on Java Persistence Facet Optionally add via the Data Source Explorer
Generate Entity Bean Generate from existing tables in database Right-click on EJB project > JPA Tools > Generate Entities
Entity Bean Support Content Assist (Ctrl + Space) for Annotations JPA Details view
Configure App Server Data Source Application server and database specific
<?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
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
Agenda
EJB Overview WTP Overview JST Overview Workspace Setup EJB Development
Entity Bean Session Bean Session Bean Client
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
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
Test
http://localhost:8080/TicketWeb/TicketServlet
Agenda
EJB Overview WTP Overview JST Overview Workspace Setup EJB Development
Entity Bean Session Bean Session Bean Client
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
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
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/
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
Questions ?
Please fill out your evaluations. Slides can be found at http://www.juddsolutions.com/ew2008/