Академический Документы
Профессиональный Документы
Культура Документы
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2014, Oracle and/or its affiliatesฺ
u se
to
B E ense
R NA le lic
B E rab
I L AR nsfe
A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
B ER ailฺc tude
RO hotm this S
a b e@
er n
a r b
g u il
(r a
BS Grupo SฺAฺCฺ
Objectives
T
B ER ailฺc tude
RO hotm this S
a b e@
er n
a r b
g u il
(r a
T
B ER ailฺc tude
RO hotm this S
a b e@
er n
a r b
g u il
(r a
Java EE Components
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2014, Oracle and/or its affiliatesฺ
EJB Container
Entity
Components
Web Container
EJB
Components Database
JSP
Pages Servlets
Application
Client
Container
u se
to
B E ense
R NA le lic
B E rab
App Client
I L AR nsfe
A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
R ilฺc ude
B E a t
Java EE Components
RO hotm this S
A component in the@ Java EE platform is not necessarily a class, but is more commonly a
e
ab and interfaces that implement a self-contained unit of functionality.
grouping of classes
The Java r n
eEE model defines a number of different component types, each of which is
a r b
g u il
customized to fulfill a specific need. The figure in the slide illustrates the primary Java EE
(ra component types in their respective containers.
The Java EE component types include:
• Session beans
• Entity classes
• Message-driven beans
• Servlets
• Components that are based on JSP technology
• Encapsulation by a container
• Support for local and distributable component interactions
• Location transparency
• Component references obtained using a naming system
u se
to
B E ense
R NA le lic
B E rab
I L AR nsfe
A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
R ilฺc ude
B E
Java EE Component
o t ma is St
RO Characteristics
The following three @ h describe
slides ththe component-based application framework that is
supported by the a e EE specification.
bJava
er n
la r b
g u i
(ra
T
R ilฺc ude
B E t
Component StateO
tma his S
R andhProperties
o
The manner in which @a component t manages state or defines properties can have implications
e
ab or on how it can be used within the Java EE framework.
on its performance
Component r n
e State: Components may have state. However, there are certain performance
a r b
g u il
advantages that follow from the assumption that some components have no state.
(r a Specifically, the component infrastructure can cycle a client’s method calls to different
instances of the component on different hosts. This cycling is advantageous for load
balancing and fault tolerance. Components may be designed to be intrinsically stateless or
stateful. Other component types may have both stateless and stateful forms.
Component Properties: A property may be represented internally by an instance variable,
but this is irrelevant to a component’s clients. In the Java programming language, properties
are typically modeled as accessor and mutator method pairs. For example, the getName and
setName methods represent the name property.
Encapsulated Components
programming.
• Java EE encapsulates components in containers that:
– Provide lifecycle management
– Isolate components from other components
– Isolate components from the runtime environment
u se
to
B E ense
R NA le lic
B E rab
I L AR nsfe
A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
B ER ailฺc tude
RO hotm this S
a b e@
er n
a r b
g u il
(r a
Component Proxies
proxies.
• There is no direct reference to the component.
• The new() operator should not be called on the
component.
• The Java EE container provides the proxy.
• A proxy allows the container to intercept method calls and
provide container-based functionality such as security
checks and transaction management. u se
to
• Some components require the developer to writeBan E ense
interface for the proxy. Java EE 6 eliminates N A licfor
the need
R
E rable
the interface in some cases. R B
ILA trans fe
U
S AG non-
Copyright © 2011,E S Uand/or itssaffiliates.
a eฺ reserved.
a Allidrights
O J om) h nt Gu
Oracle
T
R ilฺc ude
B E a t
Component Proxies
RO hotm this S
One component can@ only interact with another component through that component’s proxy.
e
ab to directly
Even if the components are located in the same Java Virtual Machine (JVM™), it is an error
r n
for one component
e instantiate another component with the new() operator or to
make r b
la direct method calls on another component’s implementation. Interfaces are frequently
u i
gused to define the functionality that will be made available by a component’s proxy.
(ra Provided that the proxy implements the same interface as the real component, the client is
unaffected by this imposition. Java EE 6 allows this proxy-based access approach to be
implemented for some components without requiring an interface. The use of proxies allows
the component to be managed by its container, which has important advantages for you.
Interface 1 Interface 2
Implementation 2
Implementation 1
u se
to
B E ense
R NA le lic
B E rab
I L AR nsfe
A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
R ilฺc ude
B E a t
RO hotmThrough
Interaction of Components
i s SInterfaces
The figure in the slide
@ th Java EE application components interact through
illustrates how
interfaces. abe
e rn implementations are programmed against the other’s public interface instead
Two component
b
of
u i lar the concrete implementation.
against
g
(ra
distributable.
• Local: The application server makes components available
to each other in the same JVM.
• Distributable: The application server provides an RMI
infrastructure by which components communicate.
Both strategies have associated costs and benefits.
u se
to
B E ense
R NA le lic
B E rab
I L AR nsfe
A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
B ER ailฺc tude
RO hotm this S
a b e@
er n
a r b
g u il
(r a
Interface2 Interface2
Stub Skeleton u se
to
B E ense
Component 1
R NA Component
l e lic 2
B E rab
I L AR nsfe
A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
R ilฺc ude
B E
RO hotand
Distributed Components ma RMI i s St
To support distributable
@ component th interaction, the application server must provide an RMI
infrastructure atob e communication. Because the Java EE component model allows a
support
n
er of interface from implementation, it is straightforward to provide an RMI
strict separation
la r b
infrastructure in a way that is mostly transparent to you.
g u i
(ra The figure in the slide shows the following:
• Component1 interacts with Component2 through its interface, Interface2.
• For distributed components, Interface2 is implemented by a stub.
• The stub contains the communication logic that allows it to make remote method calls.
• Component2 is unaware that its methods are not being called directly by Component 1.
In fact, the methods for Component2 are called on behalf of Component1 by a skeleton.
• The stub and the skeleton jointly implement the communications infrastructure.
design issues:
• Marshalling and unmarshalling of arguments and return
values
• Passing distributed exceptions
• Passing security context and transaction context
u se
to
B E ense
R NA le lic
B E rab
I L AR nsfe
A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
R ilฺc ude
RMI InfrastructureO BE m
Design a
Issues St
R o t i s
h
Marshalling and unmarshalling
@ thof arguments and return values: Java programming
n a be forms part of this process. However, serialization alone is not sufficient
language serialization
passed r b er distributed
if the RMI infrastructure
between
must be language-independent. Nevertheless, objects that are to be
components must normally be serializable
u i la
g
(ra Passing distributed exceptions: When the components are distributed, error conditions
might arise that are independent of the application logic itself, such as a network
disconnection. Normally, the caller can expect to catch a java.rmi.RemoteException in
such circumstances.
Passing security context and transaction context between the caller and the target:
There is information to supply, along with the method call, that is distinct from arguments and
return types. For example, the target component may need to ensure that the caller has the
access rights to invoke the method.
An application server must support IIOP (RMI Protocol), which is part of the CORBA
specification set. IIOP ensures that applications based on EJB components are interoperable
with CORBA services. However, there is nothing to prevent a server vendor from supporting
protocols in addition to IIOP. For example, some vendors support RMI with Java Remote
Method Protocol (JRMP) as well.
calling conventions.
Local Distributable
Components Components
Passing arguments Arguments are Arguments are
passed in shared passed by value.
memory.
Modifying the The target The target
caller’s instance component can component cannot
u se
modify the caller’s modify the caller’s to
instance. E ense
instance.
B
R NA le lic
Arguments that are themselves distributableBcomponents E rab are
an exception to these rules. These arguments I L AR nare s fepassed by
reference. A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
R ilฺc ude
B E t
tma his SInteraction
RO hoComponent
Local and Distributable
There is one exception @ to the rulest shown in the table in the slide. Arguments that are
ab e
themselves distributable components are always passed by passing a stub, regardless of
whether the e r n
components are local to one another. Because a stub is passed, the object to
which r b
la it is passed can call methods over the wire onto the caller’s instance of the object.
g u i
(ra
u se
to
B E ense
R NA le lic
B E rab
I L AR nsfe
A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
B ERloadasharing
i lฺc between
t u de servers may be achieved with local
O otm is S
Note: Fault tolerance and
components by R h advanced
using the thapplication
features of an application server such as Glassfish. Load
balancing, session
b e @
replication, and server clustering do not require remote
components. r a
nCheck the advanced features of your application server, because these features
b e
u i lar required by the Java EE specification.
are not
( rag
Location Transparency
T
B ER ailฺc tude
RO hotm this S
a b e@
er n
a r b
g u il
(r a
Interface 2
2
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2014, Oracle and/or its affiliatesฺ
Lookup
1
Component 1 Naming Publish
Service
Interface 1
3
Component 2
u se
to
B E ense
R NA le lic
B E rab
I L AR nsfe
A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
R ilฺc ude
B E t
Naming Services O
R in the o ma is SModel
Component
t
In the Java EE component
@ h model,tha component requires a way to get a reference to another
n a be without making use of the actual implementation. The facility to get a
component’s interface
r another component’s interface is provided by a naming service. An application
referenceeto
b
server
i r
la provides its components with a central repository of components that are accessible by
u
gname.
(ra The figure in the slide shows the process of using the naming service to look up reference
information. The three steps can be described as follows:
1. When the application is deployed, all of the components that need to be made
accessible to clients are registered with the naming service. In the example,
Component2 is published. This implements Interface2.
2. Component1 can only make method calls on Component2 through Interface2. To get a
reference to Interface2, Component1 performs a lookup using the central naming
service that has the logical name of Component2.
3. The naming service supplies an instance of a component that implements Interface2.
The object that is supplied is not necessarily an instance of Component2. The object
might be a proxy for Component2. Component1 can then call methods on Component2
using Interface2.
T
R ilฺc ude
B E
Use of JNDI API inOthe Java a
R hotm EEthComponent i s St Model
Only a subset of the@
full API is required when JNDI API is used in the context of a Java EE
application. ab e
e rn the protocol has no effect on the application developer, because the API
In mostbcases,
i lar these details.
conceals
u
g
(ra
T
B ER ailฺc tude
RO hotm this S
a b e@
er n
a r b
g u il
(r a
u se
to
B E ense
R NA le lic
B E rab
I L AR nsfe
A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
B ER ailฺc tude
RO hotm this S
a b e@
er n
a r b
g u il
(r a
T
B ER ailฺc Object
Configuring the InitialContext t u de
RO hotm this S
When you use the JNDI@ API outside of the context of an application server, you may be
required to supply e
b configuration information. This information varies from one naming service
ausually
to another,
e r n
but two pieces of information are required:
r b
•ilaThe name of a class that implements the underlying naming protocol
g u
(ra • A Universal Resource Locator (URL) that specifies the location of the naming service
This information is typically supplied in the form of name-value pairs that are passed in a
Hashtable object to the InitialContext constructor or as a properties file that is read
automatically in the InitialContext constructor.
The code snippet in the slide shows an example of how to configure a naming context for an
application server. Remember that this configuration is only required for access to JNDI when
using a client component located outside the Java EE application server host. A properties file
may be used in place of programmatic configuration.
u se
to
B E ense
R NA le lic
B E rab
I L AR nsfe
A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
B ER ailฺc tude
RO hotm this S
a b e@
er n
a r b
g u il
(r a
T
R ilฺc ude
B E t
Narrowing and Remote
RO hoObjectstma his S
Nonremote objects: @ For example, t connections to relational databases are obtained in the
form of DataSource e
abshows objects (javax.sql.DataSource). The code snippet under the first
bullet in the
e r n
slide the code that is required to look up a database resource named
la r
jdbc/bank.b If the object that is returned by the lookup is not of the expected type, the cast
u i
(r agfails and the caller gets a ClassCastException.
Remote Objects: The result of the lookup requires narrowing to the appropriate type. This
narrowing is to ensure future compatibility with a broad range of RMI infrastructures. Some
application servers allow remote objects that are looked up with JNDI to be cast. The code
snippet in the slide shows narrowing.
Remember that when the client of a Java EE component asks for a local reference instead of
a remote reference, the result of the JNDI API lookup is not a remote object and will never
require narrowing.
T
R ilฺc ude
B E
Using a Component
R O Context
o t mato Locate
i s St Components
Java EE EJB components
@ h typically th have a reference to an EJBContext object that is used to
provide several b
a e pieces of information. The EJBContext object:
critical
n
er already present in an EJB component
• Isbusually
r
•ilaProvides access to environmental data and manipulation, such as security information,
u
g transaction control, and resource lookup
(ra
• Works in a similar way to a JNDI Context
• Performs JNDI lookups within the java:comp/env JNDI Context and can be used to
locate EJB references, DataSources, and any other resource reference that can be
stored in JNDI
• Removes the need to repeatedly call a new InitialContext method and simplifies
exception handling by only causing runtime exceptions
An EJBContext object can be used to look up EJB 2.1 Home references. Even when looking
up EJB 2.1 Remote Home references using the component context, the use of
PortableRemoteObject.narrow is not required.
T
R ilฺc ude
B E
Using Dependency
ROInjection
o t mato Locate
i s St Components
Previously, the design
@ h name
pattern th for dependency injection was Inversion of Control. The
n a be
idea behind dependency injection is to remove the need for the developer to repeatedly write
resourcee r
lookup code. Resource lookup in Enterprise Java is typically done with JNDI.
l a rb injection eliminates JNDI coding. Dependency injection was limited to being
Dependency
i
a g u within certain types of components in Java EE 5. Java EE 5 applications sometimes
used
( r required a mixture of dependency injection and JNDI API usage. Java EE 6 enhances
dependency injection support, thus eliminating the need for almost all JNDI use by application
developers.
Annotations provide a way to embed extra data about classes, variables, and methods in
source code and also in compiled class files. This extra data added to class files can be
ignored by the Java Runtime Environment if it is not needed. Software such as a Java EE 6
application server can check for the presence of annotations using the Java reflections
package.
annotations and dependency injection replaced the need for most deployment descriptor
information.
u se
to
B E ense
R NA le lic
B E rab
I L AR nsfe
A GU on-tra
S US s a n deฺ
J E
) h a Gui
R TO com ent
O BE mailฺ Stud
R hot this
a b e@
er n
a r b
g u il
(r a
Synchronous Asynchronous
T
R ilฺc ude
B E
RO hotm thiModel
Asynchronous Communication a
s St
There are two basic@ ways that a component can interact with other components,
synchronouslyaor e
b asynchronously. Although each style of interaction has its place in the Java
EE programming
e r n model, the asynchronous model, in some cases, provides distinct
la r b
advantages.
g u i
(ra Synchronous interactions might not be suitable for operations that take an extended time to
complete or that require a high guarantee of service.
In asynchronous communication, request-notification semantics allows an application to
support operations that can take a long time to complete, and also reduces coupling between
components.
Asynchronous Component-to-Component
Interaction
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2014, Oracle and/or its affiliatesฺ
1
Legacy Batch
Place Order Ordering System
4 2
Check Order
Status
Notify Order
Status u se
to
B
Update OrderE ense
3 NA le lic
Status
R
B E rab
I L AR nsfe
A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
R ilฺc ude
B E a t
RO hotm this S
Asynchronous Component-to-Component Interaction
The figure in the slide
@ shows an example of an application that uses asynchronous
ab e
component-to-component interactions to support a legacy system.
The steps r n
ein the slide can be described as follows:
a r b
g u il A component places an order on a legacy batch processing system on behalf of a client.
1.
(ra The legacy system processes orders in batches of one hundred, so it might take several
hours for the order to be processed.
2. When the batch processing system has completed the order, it notifies another
component.
3. This component updates a database that contains order status information.
4. If the client requests information about the status of the order, a component can check
the order status database. This last step can be performed using a synchronous
interaction, asynchronous messaging, or an email notification.
Asynchronous Messaging
T
B ER ailฺc tude
RO hotm this S
a b e@
er n
a r b
g u il
(r a
T
R ilฺc ude
B E a t
RO hotm thiof
Advantages and Disadvantages
s SAsynchronous Interactions
Reduced coupling between@ components is a standard principle of software engineering,
because the fewer e
ab dependencies that exist between components, the easier it is to manage
components e r nindependently. This benefit results in the reduced long-term costs of software
la r b
management. An asynchronous model inherently offers loose coupling.
g u i
(ra
u se
to
B E ense
R NA le lic
B E rab
I L AR nsfe
A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
R ilฺc ude
B E
Developing Java EE
o t ma is St
RO Applications
Roles include system @ h
architects, h
tcomponent developers, and application assemblers.
ab e
e r n
a r b
g u il
(ra
Java EE Roles
T
R ilฺc ude
B E a t
Java EE Roles O
R hotm this S
The Java EE specification
@ defines several roles that are involved in the development,
deployment, and e
abmanagement of an enterprise application. Although most organizations have
strategies e r
forndividing up the work between different members of a project team, the Java EE
la r b
specification goes as far as mandating, to a degree, how this is to be done. Java EE roles
u i
ginclude:
(ra Application component provider: The application component provider develops Java EE
components such as EJB components, web components, and possibly resource adapters.
The output of this role is compiled classes and XML deployment descriptors. The descriptors
might be incomplete with respect to the finished system. The output from this process can be
used on any Java EE platform-compliant environment. Application component providers
produce vendor-neutral output.
Application assembler: The application assembler takes completed Java EE components
and assembles them into a deployable application. The components themselves can be from
various sources, including sources from outside of the organization. The application
assembler resolves cross-references between components and configures the components to
suit the application as a whole. Because of simplified packaging rules and support from tools,
this role has become less critical.
Tool provider: The tool provider implements development, packaging, assembly, and
deployment tools.
Product provider: Product providers are vendors of application servers and the supporting
hardware and software for those servers.
u se
to
B E ense
R NA le lic
B E rab
I L AR nsfe
A GU on-tra
S US s a n deฺ
J E
) h a Gui
R TO com ent
O BE mailฺ Stud
R hot this
a b e@
er n
a r b
g u il
(r a
Java EE Roles
u se
to
B E ense
R NA le lic
B E rab
I L AR nsfe
A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
R ilฺc ude
B E a t
RO hotm this S
Java EE Role Distinctions
For the purposes of@ this course, two role distinctions are important:
e
ab between the tool provider and the product provider: Most vendors
• The distinction
e r n
ofbapplications servers that are based on Java EE technology supply assembly and
a r
il deployment tools with their products. However, the standards-based nature of the Java
g u
(ra EE specification allows a developer to use tools from third-party tool providers if they so
desire. Application components that are developed and assembled according to the
Java EE specification should run on any compliant platform.
• The distinction between the component provider, application assembler, and
deployer: This distinction is operative throughout the Java EE specification, and is
fundamental to this course as well. Remember that although the same person can be a
developer, assembler, and deployer, these are separate roles with defined
responsibilities. For example, the component provider may use an environment variable
within the application code that the deployer sets at deployment time.
• Designing
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2014, Oracle and/or its affiliatesฺ
• Coding
• Creating deployment descriptors
• Packaging
• Assembly
• Deployment
u se
to
B E ense
R NA le lic
B E rab
I L AR nsfe
A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
R ilฺc ude
B E
RO haoJava
Steps for Developing
s St
tmaEEhiApplication
Developing a Java EE @ application t typically requires performing the following tasks:
Designing: As
e
ainb any project, design is one of the most critical steps. Simply using the Java
r n
e framework resolves many design issues, such as how to apply security or
EE application
a r b
g u il
transaction management in an application. Java EE design typically involves a higher level of
(ra abstraction, such as deciding on what set of components to use to implement the presentation
tier or the business logic.
A system architect designs the application architecture and specifies component interfaces. A
well-defined set of component interfaces at the design step can make all of the following steps
go relatively smoothly. The steps required to design and architect a Java EE application are
covered in the course titled Developing Architectures for Enterprise Java Applications.
@ h th
Deployment: The
a eapplication must be deployed to the application server either manually or
btool.
r
using a vendor’s
e n This step typically involves some vendor-specific configuration of the
b
r components or the runtime environment, such as load-balancing. Most server
application
l a
u i
vendors provide a tool to accomplish deployment.
( rag
Assemble
– Client Module
– EJB Component Module
– Web Module
Application
Components – Resource Module
Application Application
Component Assembler
Provider
RAR
ejb
u se
WAR
to
Deployer B
EAR E ense
NA le lic
JAR
R
E rabApplication
Deployment B
Applications
Tool
I L AR nsfe Server
A GU on-tra
S an
Copyright © 2011,E S U
Oracle and/oraitssaffiliates. All
i d eฺ
O J om) h nt Gu
rights reserved.
T
R ilฺc ude
B E
Java EE Application
RO Development
o t ma is ProcessSt
The figure in the slide
@ h
illustrates th application components are assembled into application
how
modules that are a e deployed as an application to an application server.
bthen
er n
la r b
g u i
(ra
Development Tools
T
R ilฺc ude
B E a t
Development Tools
RO hotm this S
You can create Java @EE technology components using a variety of tools, such as text editors
e
b editing, command-line compilers, deployment and assembly tools, or
for coding andafile
integrated e r n
development environments (IDEs) that manage the entire iterative development
cycle r b
la under the umbrella of a single application.
u i
(r agThe Netbeans and Eclipse IDEs provides all of these features and more. IDEs may provide
other features, such as database exploration, entity class creation from existing database
structure, and advanced refactoring capabilities. Many IDEs are extensible using plug-ins,
which provide potentially unlimited capabilities.
T
B ER ailฺc tude
RO hotm this S
a b e@
er n
a r b
g u il
(r a
development project:
• WAR files
• JAR files
• RAR files
• EAR files
Java EE 6 allows an EJB component to be packaged in a WAR
file.
u se
to
B E ense
R NA le lic
B E rab
I L AR nsfe
A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
R ilฺc ude
B E t
a EESApplications
RO hotm Java
Configuring and Packaging
i s
th defines the characteristics and operating requirements
Each type of archive @ file declaratively
of the archived
n a be
components by using a deployment descriptor.
Java EE b r
eapplication components are generally created in modules that serve as the basis for
the a r
ilconstruction of an archive file. A Java EE module consists of one or more Java EE
g u
(ra components for the same container type and one component deployment descriptor of that
type. For example, EJB components can be developed as part of an EJB module that is
subsequently used to create an EJB JAR file.
Web Application
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2014, Oracle and/or its affiliatesฺ
Bean Classes
se
Dynamic Content Tag Libraries
to u
B E ense
NA le lic
Servlet
R
E rab
Controllers
B
I L AR nsfeAuxiliary Classes
A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
R ilฺc ude
B E a t
Web Archive FilesO
R hotm this S
The figure in the slide@ shows the fundamental elements that constitute a web application.
e
ab in the slide only shows one icon for each element or component type, a
Although the diagram
r n
e may contain hundreds of individual elements.
web application
a r b
g u il
(ra
Static Content
WEB-INF/
ejb.xml u se
to
classes/
B E ense
R NA le lic
lib/
B E rab
I L AR nsfe
A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
R ilฺc ude
B E
Web Archive File O
R Creation
o t ma is St
As illustrated in the @figure th the contents of a web application are stored as a web
h in the slide,
n be
archive file foradistribution and incorporation as part of a deployable Java EE application.
A web b r
e file uses a .war file extension.
archive
l a r
iaddition
a g u
In to allowing EJB components to be placed in the classes directory of a WAR, Java
(r EE 6 allows library JAR files that contain EJB components to be placed in the WEB-INF/lib
folder of a .war file. A library of EJB components is not considered a stand-alone enterprise
module.
u se
to
B E ense
R NA le lic
B E rab
I L AR nsfe
A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
B ER ailฺc tude
RO hotm this S
a b e@
er n
a r b
g u il
(r a
WAR
File
Helper u se
Classes to
JAR File
B E ense
Deployment
Descriptor R NA le lic
B E rab
AR nsfe
RAR
File
I L
A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
R ilฺc ude
B E
Enterprise Archive
ROFiles o t ma is St
The super archive is@ called th
h an enterprise archive or EAR file. These files are usually given
names that endb e
a in .ear.
EAR files r n
eare structured in the same way as Java Archive files. The EAR file contains EJB
a r b
g u il
component archive files, web component archive files, resource adapter archive files, and
(ra client archive files.
Deployment Descriptors
Deployment descriptors:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2014, Oracle and/or its affiliatesฺ
T
R ilฺc ude
B E a t
RO hotm this S
Deployment Descriptors
For example, the EJB @specification indicates that an EJB deployment descriptor must be a file
e
b that is located in a META-INF directory in the EJB JAR file or be
called ejb-jar.xml
r
located inethenaWEB-INF directory in a WAR.
r b
la Deployment descriptors are optional beginning with Java EE 5. Developers can use
g u i
Note:
(ra in-code annotations to configure components. If present deployment descriptors override
in-code annotations.
A component or application deployment descriptor may specify:
• The transaction management strategy
• The authorization requirements, or who can do what to the component
• The deploy-time configuration variables
• The mapping to other components
• The external resource access dependencies
Summary
T
R ilฺc ude
B E a t
Summary
RO hotm this S
Component-based development
@ is a key feature of the Java EE platform. The Java EE model
e
nab components have some or all of the following essential characteristics,
defines a number of different component types, each customized to fulfill a specific need.
Java EE e r
technology
l a rb on the component type:
depending
i
a g u• State and properties
(r
• Encapsulation by a container
• Strict separation of interface from implementation
• Support for local and distributable component interactions
• Location transparency
• Component references obtained using a naming system
There are two basic ways that a component can interact with other components,
synchronously or asynchronously. Although each style of interaction has its place in the Java
EE programming model, the asynchronous model, in some cases, provides distinct
advantages.
u se
to
B E ense
R NA le lic
B E rab
I L AR nsfe
A GU on-tra
S US s a n deฺ
J E
) h a Gui
R TO com ent
O BE mailฺ Stud
R hot this
a b e@
er n
a r b
g u il
(r a
Quiz
u se
to
B E ense
R NA le lic
B E rab
I L AR nsfe
A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
R ilฺc ude
B E a t
Answer: c, d
RO hotm this S
a b e@
b e rn
u i lar
(r ag
Quiz
infrastructure?
a. Passing SQL
b. Parsing strings
c. Marshalling and unmarshalling
d. Passing distributed exceptions
u se
to
B E ense
R NA le lic
B E rab
I L AR nsfe
A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
R ilฺc ude
B E a t
Answer: c, d
RO hotm this S
a b e@
b e rn
u i lar
(r ag
Quiz
transparency?
a. The location is defined by a universally accessible URL.
b. The calling component caches a proxy location to the
target component.
c. In any component to component interaction, the calling
component is not concerned with the physical location of
the target component.
d. In any component to component interaction, the calling u se
to
E ense
component resolves the physical location of the target
B
component using well defined algorithms. RNA lic
B E rable
I L AR nsfe
A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
B ER ailฺc tude
Answer: c
RO hotm this S
a b e@
er n
a r b
g u il
(r a
Quiz
u se
to
B E ense
R NA le lic
B E rab
I L AR nsfe
A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
B ER ailฺc tude
Answer: c
RO hotm this S
a b e@
er n
a r b
g u il
(r a
Quiz
context?
a. Context c = new Context();
b. InitialContext c = new Context();
c. Context c = new InitialContext();
d. InitialContext c = new InitialContext();
u se
to
B E ense
R NA le lic
B E rab
I L AR nsfe
A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
B ER ailฺc tude
Answer: c
RO hotm this S
a b e@
er n
a r b
g u il
(r a
Quiz
dependency injection?
a. JDBC
b. EJB
c. Java Interfaces
d. Java Annotations
u se
to
B E ense
R NA le lic
B E rab
I L AR nsfe
A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
B ER ailฺc tude
Answer: d
RO hotm this S
a b e@
er n
a r b
g u il
(r a
Quiz
T
B ER ailฺc tude
Answer: c
RO hotm this S
a be@
b e rn
i lar
ag u
(r
Quiz
a. Deployer
b. Application Analyst
c. R System Administrator
d. R Application component provider
u se
to
B E ense
R NA le lic
B E rab
I L AR nsfe
A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
B ER ailฺc tude
Answer: b
RO hotm this S
a b e@
er n
a r b
g u il
(r a
Quiz
application development?
a. Code, test, code, test, package, deploy
b. Design, code, configure, package, assemble, deploy
c. Code, test, code, configure, package, assemble, deploy
d. Code, configure, package, assemble, deploy, test, code
u se
to
B E ense
R NA le lic
B E rab
I L AR nsfe
A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
B ER ailฺc tude
Answer: b
RO hotm this S
a b e@
er n
a r b
g u il
(r a
Quiz
a. tar
b. jar
c. war
d. ear
u se
to
B E ense
R NA le lic
B E rab
I L AR nsfe
A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
B ER ailฺc tude
Answer: a
RO hotm this S
a b e@
er n
a r b
g u il
(r a
Practice 2: Overview
u se
to
B E ense
R NA le lic
B E rab
I L AR nsfe
A GU on-tra
S an
Copyright © 2011,E S U itssaffiliates. All
Oracle and/ora i d eฺ
O J om) h nt Gu
rights reserved.
T
B ER ailฺc tude
RO hotm this S
a b e@
er n
a r b
g u il
(r a