Session Beans - PowerPoint PPT Presentation

1 / 70
About This Presentation
Title:

Session Beans

Description:

Method Ready Pool. state entered when container needs instance ... { throw new BankException('account id not found:' id); return account; ... – PowerPoint PPT presentation

Number of Views:84
Avg rating:3.0/5.0
Slides: 71
Provided by: JimSta1
Category:
Tags: beans | in | pool | session | thrown

less

Transcript and Presenter's Notes

Title: Session Beans


1
Session Beans
2
Topics
  • Understanding Session Beans
  • Implementing Session Beans
  • Physical Construction

3
Understanding Session Beans
4
Associated Design Patterns
  • Sun Java Center J2EE Pattern Catalog
  • http//developer.java.sun.com/developer/restricted
    /patterns/J2EEPatternsAtAGlance.html
  • Session Façade
  • http//developer.java.sun.com/developer/restricted
    /patterns/SessionFacade.html
  • Value Object Assembler
  • http//developer.java.sun.com/developer/restricted
    /patterns/ValueObjectAssembler.html

5
Session Façade
  • Context
  • multi-tiered application
  • non-trivial business logic and data
  • Problem
  • potential tight coupling between clients and
    complex business objects
  • too many method invocations between clients and
    business objects
  • business methods exposed for misuse by clients

6
Example Workflow Task
7
Session Façade
  • Forces
  • hide complex interactions behind a simple client
    interface
  • reduce the number of business objects exposed to
    the client across the network
  • hide implementation, interactions, and
    dependencies of business components
  • Solution
  • Use a Session Bean to encapsulate the
    interactions required with the business objects

8
Session Beans Eliminate Workflow Complexity in
Client
9
Session Façade Participants
10
Session Facade
  • Consequences
  • Simplifies complex systems
  • May appear to be a no value pass-thru in simple
    systems
  • should involve more that one business object per
    facade
  • should have more than one façade per system
  • Decouples the business objects from being aware
    of one another
  • Improves perceived network performance
  • Centralizes security and transactions

11
Use Cases and Session Beans
  • Session Bean per Use Case too fine grain
  • CreateAccountEJB
  • DepositEJB
  • WithdrawEJB
  • TransferEJB
  • Group cohesive Use Cases into a larger-grain
    Session Bean
  • TellerEJB
  • createAccount(), deposit(), withdraw(), transfer()

12
Use of Session versus Entity Beans
  • Session Beans
  • implementation of a task
  • interaction between other beans
  • database access
  • usually read only
  • interacts with data generally at the
    collection/table level
  • examples
  • TaxDistrict.calcTax(double cost)
  • Teller.transfer(long fromAccount, long toAccount,
    double amount)
  • Registrar.listStudents(String course)

13
Use of Session versus Entity Beans (cont.)
  • Entity Beans
  • represent shared data in the database
  • provide a type-safe, complete view of shared
    information
  • interacts with data generally at the individual
    object/row level
  • examples
  • Account, Student
  • Account.setOwner(String taxId),
    Account.getOwner()
  • Account.withdraw(double amount),
    Account.deposit(double amount)

14
Stateless/Stateful Session Beans
  • Stateless
  • maintains no conversational state
  • each method is ignorant of what went before it
    and what will happen after it
  • maintains implementation state
  • sharable between separate client invocations
  • a set of procedures or batch commands that take
    in a set of parameters and return a result

15
Stateless/Stateful Session Beans
  • Stateful
  • maintains conversational state
  • object can cache values between calls
  • ex. iterator
  • idle timeout period or client command ends
    lifetime
  • maintains implementation state
  • not sharable between separate clients/objects
  • all resources are allocated to perform the work
    of one Stateful Session bean instance. That
    instance is tied to the state of the client
  • able to react to transaction states
  • ex. Publish error message on transaction rollback

16
Stateful Session Bean Example (Iteration)
17
Stateless/Stateful
  • Stateless
  • can contain cached implementations
  • JDBC DataSources
  • JMS Publishers
  • cached EAI state
  • all non-visible to calling client
  • Stateful
  • may contain all of the above and add client
    conversational state

18
Stateless/Stateful
  • Stateless
  • Cheapest to implement, deploy, scale
  • Stateful
  • should be avoided
  • should only be used within the scope of a single
    HttpRequest
  • should not be used at HttpSession Scope
  • multiple threads would access same instance

19
Stateless Session Bean Lifecycle
20
Stateless Session Bean States
  • Does Not Exist
  • no instance instantiated
  • default state at container startup
  • Method Ready Pool
  • state entered when container needs instance
  • instance(s) may be instantiated at container
    startup
  • one or more instances may be used to service
    business methods
  • container may optionally instantiate or remove
    instances as it deems necessary

21
Stateless Session Bean Transitions
  • Does Not Exist -gt Method Ready Pool
  • methods invoked
  • Class.newInstance() (default constructor)
  • usually not provided/no behavior
  • place all initialization code in
    setSessionContext or ejbCreate
  • setSessionContext(SessionContext ctx)
  • establish EJBs reference to container (ctx)
  • ejbCreate()
  • allocate any bean (not object) resources
  • work here can also be done in setSessionContext()

22
Stateless Session Bean Transitions
  • Method Ready Pool -gt Method Ready Pool
  • taken from bean pool
  • assigned to EJB Object for the lifetime of the
    method
  • method invoked
  • object resources allocated/released during scope
    of call
  • returned to bean pool
  • Method Ready Pool -gt Does Not Exist
  • methods invoked
  • ejbRemove()
  • release any bean resources

23
Stateless Session Bean Resources
  • Stateless Session Beans not subject to
    activation/passivation
  • ejbActivate/ejbPassivate never called
  • may allocate bean resources for the lifetime of
    bean
  • java.sql.Connection
  • RMI Stub
  • RMI Servers
  • other EJB Homes
  • other EJB Objects
  • client socket

24
Stateful Session Bean Lifecycle
25
Stateful Session Bean States
  • Does Not Exist
  • Method Ready State
  • state where bean can satisfy business method
    requests
  • caused by
  • client creating instance (home.create())
  • client invoking business method (object.method())

26
Stateful Session Bean Transitions
  • Does Not Exist -gt Method Ready
  • methods invoked
  • Class.newInstance() (default constructor)
  • usually not provided/no behavior
  • place all initialization code in
    setSessionContext or ejbCreate
  • setSessionContext(SessionContext ctx)
  • establish EJBs reference to container (ctx)
  • ejbCreate()
  • allocate any bean/object resources
  • work here can also be done in setSessionContext()

27
Stateful Session Bean Transitions
  • Method Ready -gt Passive
  • caused by container limited in resources
  • instance fields written to persistent storage
  • method invoked
  • ejbPassivate()
  • release any bean/object resources
  • non-transient, non-serializable fields should be
    set to null

28
Stateful Session Bean Transitions
  • Passive -gt Method Ready
  • caused by client invoking business method while
    bean in passive state
  • methods invoked
  • ejbActivate()
  • reallocate any bean/object resources
  • initialize any transient fields
  • passivation/activation does not follow
    de-Serialization semantics for setting transients
    to their default/zero values
  • transient fields can contain arbitrary values
    following activation

29
Stateful Session Bean Transitions
  • Method Ready -gt Does Not Exist
  • client removing object (object.remove())
  • ejbRemove() invoked
  • release any bean/object resources
  • container timing out inactive bean
  • timeouts are expressed in vendor-specific ways
  • ejbRemove() optionally invoked
  • business method throws SystemException
  • any unchecked exception including EJBException
  • wrap non-business exceptions in EJBExceptions
  • ejbRemove() not invoked

30
Article
  • Stateful Session Beans Beasts of Burden
  • 10/02/2001
  • http//www.onjava.com/pub/a/onjava/2001/10/02/ejb.
    html
  • Tyler Jewell, Principal Technology Evangelist for
    BEA Systems
  • Use like HttpSession in non-Web applications
  • Use with large client caches when Web Container
    does not support HttpSession resource management
  • Use when change in cache data depends on
    transaction state HttpSessions do not support
    change rollbacks.
  • Do not use as server-side data caches too many
    issues related to caching with limited inherent
    support

31
Implementing Session Beans
32
Session Bean Home Interface
  • Used to create instance
  • Stateful Session Bean Home actually creates
    instance with associated stub
  • multiple create()s allowed in Home
  • Stateless Session Bean Home creates stub to
    possibly shared instance
  • create() - is only method allowed in Home
  • Remote and Local forms
  • Remote must throw java.rmi.RemoteException
  • Local may not throw java.rmi.RemoteException

33
Stateless Home Example
  • package ejava.examples.ejb.session.bean
  • import javax.ejb.EJBHome
  • import javax.ejb.CreationException
  • import java.rmi.RemoteException
  • public interface TellerRemoteHome extends EJBHome
  • public TellerRemote create() throws
    CreationException, RemoteException
  • package ejava.examples.ejb.session.bean
  • import javax.ejb.EJBLocalHome
  • public interface TellerLocalHome extends
    EJBLocalHome
  • public TellerLocal create() throws
    CreationException

34
Stateful Home Example
  • package ejava.examples.ejb.session.bean
  • import javax.ejb.
  • public interface QueryLocalHome extends
    EJBLocalHome
  • QueryLocal create(int maxrows) throws
    CreateException
  • package ejava.examples.ejb.session.bean
  • import javax.ejb.
  • import java.rmi.RemoteException
  • public interface QueryRemoteHome extends EJBHome
  • QueryRemote create(int maxrows) throws
    CreateException, RemoteException

35
Session Bean Object Interface
  • Used to invoke a function or workflow
  • Stateless interfaces may not infer conversational
    state held by object
  • Stateful interfaces may take advantage of
    conversational state
  • Remote and Local forms

36
Stateless Object Interface Example
  • package ejava.examples.ejb.session.bean
  • import ejava.examples.ejb.session.
  • import javax.ejb.EJBObject
  • import java.rmi.RemoteException
  • public interface TellerRemote extends EJBObject
  • Account getAccount(int accountId) throws
    BankException, RemoteException
  • void deposit(int accountId, double amount)
  • throws BankException, RemoteException
  • void withdraw(int accountId, double amount)
  • throws BankException, RemoteException
  • void transfer(int fromId, int toId, double
    amount)
  • throws BankException, RemoteException

37
Stateless Object Interface Example
  • package ejava.examples.ejb.session.bean
  • import ejava.examples.ejb.session.
  • import javax.ejb.EJBLocalObject
  • import java.rmi.RemoteException
  • public interface TellerLocal extends
    EJBLocalObject
  • Account getAccount(int accountId) throws
    BankException
  • void deposit(int accountId, double amount)
  • throws BankException
  • void withdraw(int accountId, double amount)
  • throws BankException
  • void transfer(int fromId, int toId, double
    amount)
  • throws BankException

38
Stateful Object Interface Example
  • package ejava.examples.ejb.session.bean
  • import javax.ejb.EJBLocalObject
  • import java.util.Collection
  • public interface QueryLocal extends
    EJBLocalObject
  • Collection getAllAccounts()
  • Collection getNext()
  • package ejava.examples.ejb.session.bean
  • import javax.ejb.EJBObject
  • import java.util.Collection
  • import java.rmi.RemoteException
  • public interface QueryRemote extends EJBObject
  • Collection getAllAccounts() throws
    RemoteException
  • Collection getNext() throws RemoteException

39
Session Bean EJB Class
  • Use to implement function or workflow
  • Local and Remote interfaces use same EJB Class
    method implementation

40
Stateless Session Bean EJB Class Example
  • public class TellerEJB implements SessionBean
  • private DataSource ds_
  • private AccountDAO dao_
  • public void ejbCreate()
  • try
  • dao_ new AccountDAO()
  • InitialContext jndi new
    InitialContext()
  • ds_ (DataSource)jndi.lookup("javacomp
    /env/jdbc/mydb")
  • catch (NamingException ex)
  • throw new EJBException(ex)

41
Stateless Session Bean EJB Class Example
  • public Account getAccount(int id) throws
    BankException
  • Connection conn null
  • try
  • conn ds_.getConnection()
  • Account account dao_.find(conn, id)
  • if (account null)
  • throw new BankException("account id
    not found" id)
  • return account
  • catch (SQLException ex) throw new
    EJBException(ex)
  • finally
  • try if (conn ! null) conn.close()
  • catch (SQLException sqlex) throw new
    EJBException(sqlex)

42
Stateless Session Bean EJB Class Example
  • public void deposit(int id, double amount)
    throws BankException
  • public void withdraw(int id, double amount)
    throws BankException
  • public void transfer(int fromId, int toId,
    double amount) throws BankException
  • public void ejbActivate()
  • public void ejbPassivate()
  • public void ejbRemove()
  • public void setSessionContext(SessionContext
    ctx)

43
Stateful Session Bean EJB Class Example
  • public class QueryEJB implements SessionBean
  • transient Connection connection_
  • transient AccountDAO dao_
  • int maxrows_
  • public void ejbCreate(int maxrows)
  • try
  • maxrows_ maxrows dao_ new
    AccountDAO()
  • Context jndi new InitialContext()
  • DataSource dataSource
    (DataSource)jndi.lookup("javacomp/env/jdbc/mydb")
  • connection_ dataSource.getConnection()
  • catch (NamingException ex) close() throw
    new EJBException(ex)
  • catch (SQLException ex) close()
    throw new EJBException(ex)

44
Stateful Session Bean EJB Class Example
  • public Collection getAllAccounts()
  • try
  • Collection accounts null
  • accounts dao_.getAll(connection_,
    maxrows_)
  • if (accounts.size() lt maxrows_)
    close()
  • return accounts
  • catch (SQLException sqlex)
  • close()
  • throw new EJBException(sqlex)

45
Stateful Session Bean EJB Class Example
  • public Collection getNext()
  • try
  • Collection accounts null
  • accounts dao_.getNext(maxrows_)
  • if (accounts.size() lt maxrows_)
    close()
  • return accounts
  • catch (SQLException sqlex)
  • close()
  • throw new EJBException(sqlex)

46
Stateful Session Bean EJB Class Example
  • public void ejbActivate() throw new
    EJBException("bean timed out")
  • public void ejbPassivate() close()
  • public void ejbRemove() close()
  • public void close()
  • try if (dao_ ! null) dao_.close()
  • catch (Exception ignored)
  • try if (connection_ ! null)
    connection_.close()
  • catch (Exception ignored)
  • connection_ null
  • public void setSessionContext(SessionContext
    ctx)

47
JNDI Environment Naming Context (ENC)
  • JNDI namespace specific to each bean type
  • Access system resources
  • DataSources, JMS Connection Factories, etc.
  • Access configuration values
  • table names, min/max values, etc.
  • configured in deployment descriptors
  • referenced by code using the special JNDI name
    javacomp/env

48
JNDI ENC Value Example
  • Deployment Descriptor (ejb-jar.xml)
  • ltenv-entrygt
  • ltenv-entry-namegttableNamelt/env-entry-namegt
  • ltenv-entry-typegtjava.lang.Stringlt/env-entry-typ
    egt
  • ltenv-entry-valuegtAccountlt/env-entry-valuegt
  • lt/env-entrygt
  • Component Java Code
  • Context jndi new InitialContext()
  • String tableName (String)jndi.lookup("java
    comp/env/tableName")

49
JNDI ENC Resource Example
  • Deployment Descriptor (ejb-jar.xml)
  • ltresource-refgt
  • ltres-ref-namegtjdbc/mydblt/res-ref-namegt
  • ltres-typegtjavax.sql.DataSourcelt/res-typ
    egt
  • ltres-authgtContainerlt/res-authgt
  • lt/resource-refgt
  • Component Java Code
  • Context jndi new InitialContext()
  • DataSource dataSource
    (DataSource)jndi.lookup("javacomp/env/jdbc/mydb")

50
JNDI ENC System Resource Example
  • Deployment Descriptor (weblogic-ejb-jar.xml)
  • ltreference-descriptorgt
  • ltresource-descriptiongt
  • ltres-ref-namegtjdbc/mydblt/res-ref-namegt
  • ltjndi-namegtcoredev/jdbc/DSlt/jndi-namegt
  • lt/resource-descriptiongt
  • lt/reference-descriptorgt
  • Deployment Descriptor (jboss.xml)
  • ltresource-refgt
  • ltres-ref-namegtjdbc/mydblt/res-ref-namegt
  • ltjndi-namegtjavacoredev/jdbc/DSlt/jndi-namegt
  • lt/resource-refgt

51
Session Bean Deployment Descriptors(ejb-jar.xml)
  • lt?xml version"1.0"?gt
  • lt!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems,
    Inc.//DTD Enterprise JavaBeans 2.0//EN'
    'http//java.sun.com/dtd/ejb-jar_2_0.dtd'gt
  • ltejb-jargt
  • ltdisplay-namegtSession Bean Bank Teller Example
    EJBlt/display-namegt
  • ltenterprise-beansgt
  • ltsessiongtlt/sessiongt
  • lt/enterprise-beansgt
  • ltassembly-descriptorgt
  • lt/assembly-descriptorgt
  • ltejb-client-jargtSessionBankEJBClient.jarlt/ejb-c
    lient-jargt
  • lt/ejb-jargt

52
Session Bean Deployment Descriptors(ejb-jar.xml)
  • ltsessiongt
  • ltejb-namegtTellerlt/ejb-namegt
  • lthomegtcorej2ee.examples.sessionbank.ejb.TellerR
    emoteHomelt/homegt
  • ltremotegtcorej2ee.examples.sessionbank.ejb.Telle
    rRemotelt/remotegt
  • ltejb-classgtcorej2ee.examples.sessionbank.ejb.Te
    llerEJBlt/ejb-classgt
  • ltsession-typegtStatelesslt/session-typegt
  • lttransaction-typegtContainerlt/transaction-typegt
  • ltenv-entrygt
  • ltenv-entry-namegtjdbc/accountTableNamelt/env-e
    ntry-namegt
  • ltenv-entry-typegtjava.lang.Stringlt/env-entry-
    typegt
  • ltenv-entry-valuegtsessionbank_Accountlt/env-en
    try-valuegt
  • lt/env-entrygt
  • ltresource-refgt
  • ltres-ref-namegtjdbc/mydblt/res-ref-namegt
  • ltres-typegtjavax.sql.DataSourcelt/res-typegt
  • ltres-authgtContainerlt/res-authgt
  • lt/resource-refgt

53
Session Bean Deployment Descriptors(ejb-jar.xml)
  • ltsessiongt
  • ltejb-namegtQuerylt/ejb-namegt
  • ltlocal-homegtcorej2ee.examples.sessionbank.ejb.Q
    ueryLocalHomelt/local-homegt
  • ltlocalgtcorej2ee.examples.sessionbank.ejb.QueryL
    ocallt/localgt
  • ltejb-classgtcorej2ee.examples.sessionbank.ejb.Qu
    eryEJBlt/ejb-classgt
  • ltsession-typegtStatefullt/session-typegt
  • lttransaction-typegtContainerlt/transaction-typegt
  • ltenv-entrygt
  • ltenv-entry-namegtjdbc/accountTableNamelt/env-e
    ntry-namegt
  • ltenv-entry-typegtjava.lang.Stringlt/env-entry-
    typegt
  • ltenv-entry-valuegtsessionbank_Accountlt/env-en
    try-valuegt
  • lt/env-entrygt
  • ltresource-refgt
  • ltres-ref-namegtjdbc/mydblt/res-ref-namegt
  • ltres-typegtjavax.sql.DataSourcelt/res-typegt
  • ltres-authgtContainerlt/res-authgt
  • lt/resource-refgt

54
Session Bean Deployment Descriptors(weblogic-ejb-
jar.xml)
  • lt!DOCTYPE weblogic-ejb-jar PUBLIC
  • '-//BEA Systems, Inc.//DTD WebLogic 8.1.0
    EJB//EN' 'http//www.bea.com/servers/wls810/dtd/
    weblogic-ejb-jar.dtd'gt
  • ltweblogic-ejb-jargt
  • ltweblogic-enterprise-beangt
  • ltejb-namegtTellerlt/ejb-namegt
  • ltreference-descriptorgt
  • ltresource-descriptiongt
  • ltres-ref-namegtjdbc/mydblt/res-ref-namegt
  • ltjndi-namegtcorej2ee/jdbc/DSlt/jndi-name
    gt
  • lt/resource-descriptiongt
  • lt/reference-descriptorgt
  • ltjndi-namegtcorej2ee/examples/sessionBank/Tel
    lerRemoteHomelt/jndi-namegt
  • lt/weblogic-enterprise-beangt
  • ltweblogic-enterprise-beangt
  • ltejb-namegtQuerylt/ejb-namegt
  • ltreference-descriptorgt
  • ltresource-descriptiongt
  • ltres-ref-namegtjdbc/mydblt/res-ref-namegt

55
Session Bean Deployment Descriptors(jboss.xml)
  • lt!DOCTYPE jboss PUBLIC
  • '-//JBoss//DTD JBOSS 4.0//EN'
    'http//www.jboss.org/j2ee/dtd/jboss_4_0.dtd'gt
  • ltjbossgt
  • ltenterprise-beansgt
  • ltsessiongt
  • ltejb-namegtTellerlt/ejb-namegt
  • ltjndi-namegtcorej2ee/examples/sessionBa
    nk/TellerRemoteHomelt/jndi-namegt
  • ltresource-refgt
  • ltres-ref-namegtjdbc/mydblt/res-ref-n
    amegt
  • ltjndi-namegtjavacoredev/jdbc/DSlt/j
    ndi-namegt
  • lt/resource-refgt
  • lt/sessiongt
  • ltsessiongt
  • ltejb-namegtQuerylt/ejb-namegt
  • ltlocal-jndi-namegtcorej2ee/examples/se
    ssionBank/QueryLocalHomelt/local-jndi-namegt
  • ltresource-refgt
  • ltres-ref-namegtjdbc/mydblt/res-ref-n
    amegt
  • ltjndi-namegtjavacoredev/jdbc/DSlt/j
    ndi-namegt

56
Integrating with Web Tier(web.xml)
  • ltweb-appgt
  • ltejb-refgt
  • ltejb-ref-namegtejb/TellerRemoteHomelt/ejb-ref-
    namegt
  • ltejb-ref-typegtSessionlt/ejb-ref-typegt
  • lthomegtcorej2ee.examples.ejb.session.bean.Tel
    lerRemoteHomelt/homegt
  • ltremotegtcorej2ee.examples.ejb.session.bean.T
    ellerRemotelt/remotegt
  • ltejb-linkgtTellerlt/ejb-linkgt
  • lt/ejb-refgt
  • ltejb-local-refgt
  • ltejb-ref-namegtejb/QueryLocalHomelt/ejb-ref-na
    megt
  • ltejb-ref-typegtSessionlt/ejb-ref-typegt
  • ltlocal-homegtcorej2ee.examples.ejb.session.be
    an.QueryLocalHomelt/local-homegt
  • ltlocalgtcorej2ee.examples.ejb.session.bean.Qu
    eryLocallt/localgt
  • ltejb-linkgtQuerylt/ejb-linkgt
  • lt/ejb-local-refgt
  • lt/web-appgt

57
Integrating with Web Tier
  • Application Server-Specific Mappings not needed
  • weblogic.xml
  • lt!DOCTYPE weblogic-web-app PUBLIC
  • "-//BEA Systems, Inc.//DTD Web Application
    7.0//EN"
  • "http//www.bea.com/servers/wls700/dtd/weblogic
    -web-jar.dtd"gt
  • ltweblogic-web-appgt
  • lt/weblogic-web-appgt
  • jboss-web-xml
  • lt!DOCTYPE jboss-web PUBLIC
  • "-//JBoss//DTD Web Application 2.4//EN"
  • "http//www.jboss.org/j2ee/dtd/jboss-web_4_0.d
    td"gt
  • ltjboss-webgt
  • lt/jboss-webgt

58
Not Yet Covered
  • Transactions
  • Security

59
Physical Construction
60
J2EE Server EAR
ltEAR applicationgt
META-INF
application.xml
ltUtil componentgt
META-INF
MANIFEST.MF
ltimplementationgt.classes
ltEJB componentgt
META-INF
MANIFEST.MF ejb-jar.xml jboss.xml weblogic-ejb-jar
.xml
ltimplementationgt.classes
61
J2EE Server EAR (cont.)
ltEAR applicationgt
ltWeb componentgt
WEB-INF
web.xml jboss-web.xml webservices.xml
classes
ltservletgt.classes
lib
ltarchivegt.jar ltimplementationgt.classes
ltpublic resourcesgt (e.g., HTML, JSP, JPEG, GIF,
etc.)
62
Manual EJB JAR Construction
  • Create the class tree
  • mkdir -p EJB_CLASS_DIR/META-INF
  • Populate the class tree
  • javac -d EJB_CLASS_DIR
  • vi EJB_CLASS_DIR/META-INF/myManifest.mf
  • Create the container-generic jar
  • jar cvfm TMP/myEJB.jar myManifest.mf
  • WebLogicCreate the container-specific jar
  • java weblogic.ejbc TMP/myEJB.jar
    EJBDIR/myEJB.jar
  • JBossNo pre-compilation available/necessary

63
Example Ant EJB JAR Construction
  • lttarget name"ejbs" depends"compile"
    description"creates ejb jar files"gt
  • ltmkdir dir"ejb"/gt
  • ltejbjar descriptordir"src
    srcdir"classes" naming"directory"
  • flatdestdir"true"gt
  • ltweblogic destdir"ejb
    classpath"classes"
  • wlclasspath"wl.classes
    newCMP"true keepgeneric"false"/gt
  • ltinclude name"package.dir//ejb-jar.
    xml"/gt
  • ltexclude name"/ejbcgen/.xml"/gt
  • lt/ejbjargt
  • lt!-- copy ejbc generated client jar files
    to clientjar directory --gt
  • ltmove todir"clientlib"gt
  • ltfileset dir"src"gt ltinclude
    name".jar"/gt lt/filesetgt
  • lt/movegt
  • lt/targetgt

64
EJB Construct Example(WebLogic
SessionBankEJB.jar)
  • jar tf sessionBankEJB.jar
  • META-INF/MANIFEST.MF
  • corej2ee/examples/sessionbank/Account.class
  • corej2ee/examples/sessionbank/BankException.class
  • corej2ee/examples/sessionbank/client/QueryAccessor
    .class
  • corej2ee/examples/sessionbank/client/TellerAccesso
    r.class
  • corej2ee/examples/sessionbank/dao/AccountDAO.class
  • corej2ee/examples/sessionbank/ejb/.QueryEJB.java.s
    wp
  • corej2ee/examples/sessionbank/ejb/QueryEJB.class
  • corej2ee/examples/sessionbank/ejb/QueryLocal.class
  • corej2ee/examples/sessionbank/ejb/QueryLocalHome.c
    lass
  • META-INF/ejb-jar.xml
  • META-INF/jboss.xml
  • META-INF/weblogic-ejb-jar.xml
  • ltBOLDgt - created by EJB developer

65
EJB Construct Example(WebLogic
SessionBankEJB.jar)
  • corej2ee/examples/sessionbank/ejb/Query_nnfjgd_ELO
    Impl.class
  • corej2ee/examples/sessionbank/ejb/Query_nnfjgd_Imp
    l.class
  • corej2ee/examples/sessionbank/ejb/Query_nnfjgd_Int
    f.class
  • corej2ee/examples/sessionbank/ejb/Query_nnfjgd_Loc
    alHomeImpl.class
  • corej2ee/examples/sessionbank/ejb/TellerEJB.class
  • corej2ee/examples/sessionbank/ejb/TellerRemote.cla
    ss
  • corej2ee/examples/sessionbank/ejb/TellerRemoteHome
    .class
  • corej2ee/examples/sessionbank/ejb/Teller_mfqou7_EO
    Impl.class
  • corej2ee/examples/sessionbank/ejb/Teller_mfqou7_EO
    ImplRTD.xml
  • corej2ee/examples/sessionbank/ejb/Teller_mfqou7_Ho
    meImpl.class
  • corej2ee/examples/sessionbank/ejb/Teller_mfqou7_Ho
    meImplRTD.xml
  • corej2ee/examples/sessionbank/ejb/Teller_mfqou7_Im
    pl.class
  • corej2ee/examples/sessionbank/ejb/Teller_mfqou7_In
    tf.class
  • _WL_GENERATED

66
EJB Construct Example (sessionBankEJBClient.jar)
  • jar tf lib/sessionBankEJBClient.jar
  • META-INF/
  • META-INF/MANIFEST.MF
  • corej2ee/
  • corej2ee/examples/
  • corej2ee/examples/sessionbank/
  • corej2ee/examples/sessionbank/client/
  • corej2ee/examples/sessionbank/client/QueryAccessor
    .class
  • corej2ee/examples/sessionbank/client/TellerAccesso
    r.class
  • corej2ee/examples/sessionbank/ejb/
  • corej2ee/examples/sessionbank/ejb/TellerRemote.cla
    ss
  • corej2ee/examples/sessionbank/ejb/TellerRemoteHome
    .class

67
Manual EAR Construction
  • jar cvf APP_DIR/myApp.ear

68
Example Ant WAR/EAR Construction
  • lttarget name"SessionBankWEB.war"gt
  • ltwar file"war/SessionBankWEB.war"
  • webxml"package.src/web/web.xml"gt
  • ltwebinf dir"package.src/web"
    includes"weblogic.xml"/gt
  • ltclasses dir"classes"
    includes"package.dir/client/.class"/gt
  • ltfileset dir"package.dir/web"
    includes".jsp"/gt lt/wargt
  • lt/targetgt
  • lttarget name"SessionBankApp.ear" depends"wars,
    ejbs"gt
  • ltear file"apps/SessionBankApp.ear"
  • appxml"src/package.dir/dd/applic
    ation.xml"gt
  • ltfileset dir"war" includes"SessionBa
    nkWEB.war"/gt
  • ltfileset dir"ejb" includes"SessionBa
    nkEJB.jar"/gt lt/eargt
  • lt/targetgt

69
Enterprise Application Construct Example
  • jar tf sessionBankApp.ear
  • META-INF/
  • META-INF/MANIFEST.MF
  • sessionBankEJB.jar
  • sessionBankWEB.war
  • sessionBankEJBClient.jar
  • META-INF/application.xml

70
Enterprise Application Example(application.xml)
  • lt!DOCTYPE application PUBLIC
  • '-//Sun Microsystems, Inc.//DTD J2EE
    Application 1.3//EN'
  • 'http//java.sun.com/dtd/application_1_3.dtd'gt
  • ltapplicationgt
  • ltdisplay-namegtSession Bean Banking Example
    Applicationlt/display-namegt
  • ltmodulegtltejbgtsessionBankEJBlt/ejbgtlt/modulegt
  • ltmodulegt
  • ltwebgt
  • ltweb-urigtsessionBankWEBlt/web-urigt
  • ltcontext-rootgtsessionBankApplt/context-roo
    tgt
  • lt/webgt
  • lt/modulegt
  • lt/applicationgt
Write a Comment
User Comments (0)
About PowerShow.com