Date post: | 24-Dec-2015 |
Category: |
Documents |
Upload: | victoria-ada-tucker |
View: | 240 times |
Download: | 0 times |
v090401 JavaEE EAR 1
EnterpriseJava
Java EE Enterprise Archive (EAR)
v090401 JavaEE EAR 2
EnterpriseJava
Goals
• Understand the purpose for an EAR• Be able to construct an EAR for developed Java EE
components
v090401 JavaEE EAR 3
EnterpriseJava
Objectives
• EAR Purpose• EAR Format
v090401 JavaEE EAR 4
EnterpriseJava
Class Loaders
• Arranged in a parent/child relationship• Requests for a class are first delegated to the parent class
loader• May access classes/resources loaded by local and parent
class loader• Do not have access to classes/resources loaded by sibling
class loaders
Parent Class Loader
Child Class Loader Child Class Loader
v090401 JavaEE EAR 5
EnterpriseJava
Application Server Class Loader
EJB AppClass Loader
Web App Class Loader
Web App Class Loader
Separate EJB/WAR Deployment
• Classes loaded by EJB Application Class Loader not seen by Web Application
• Shared implementations must be placed in both applications– WEB-INF/lib
– causes difficulty when passing object between applications that have loaded the same class
v090401 JavaEE EAR 6
EnterpriseJavaJ2EE Enterprise
Application DeploymentApplication Server Class Loader
EAR Class Loader
EJB App Class Loader
EAR Class Loader
Web App 2 Class LoaderWeb App 1 Class Loader Servlets/JSPs and lib.jars
loaded by isolated classloaders
All EJBs are loaded by a single class loader•may also include web dependent classes identified through manifest entries to promote singleton loading of classes across web applications
EJB interfaces and dependent classes identified by EJB manifests loaded by EAR’s classloader
v090401 JavaEE EAR 7
EnterpriseJava
Enterprise Application Archive (EAR)
• WAR(s)
– directory or archive
• EJB(s)
– directory or archive
• Client JAR(s)
– client applications
• Utility Classes(s)
– directory or archive
– supplies external source utility classes
– referenced through MANIFESTs
• Resource Adapters(s)
– custom resource drivers
WARWARWAR
EJBEJBEJB
EAR
META-INF/application.xml
UtilityClasses
Resource AdapterResource
AdapterResource Adapter
ClientApp
ClientAppClient
App
UtilityClasses
UtilityClasses
v090401 JavaEE EAR 8
EnterpriseJava
Directory and Archive Forms
• Exploded Directory Form– ability to modify static files (html/jsp) without redeploying
– separate server serves up content in exploded form
– simpler build environment • consistent with build environment of free versions of IDEs (Forte,
JBuilder, etc.)
• Archive File Format– easy form of distribution
v090401 JavaEE EAR 9
EnterpriseJava
application
icon
small-icon large-icon
display-name description? module+ security-role*
ejb|connector|java|web alt-dd
web-uri context-root
description?
role-name
application.xml
v090401 JavaEE EAR 10
EnterpriseJava
Element Definitions
• Application– Declares the overall enterprise application
• Deployment Tool Info– icon, display-name, description
• Modules– ejb – EJBs (Ex. EJB1.jar)
– web – web applications
– java - client applications
– connector – JCA resource adapters
v090401 JavaEE EAR 11
EnterpriseJava
Element Definitions (Cont)
• Web applications– web-uri (ex. webapp1.war)
– context-root• Name of web app’s context
• May be empty if only one webapp in the application
• alt-dd– Can override the deployment descriptor found in the module
• security-role– Define application-level security roles
v090401 JavaEE EAR 12
EnterpriseJava
application.xml Example
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE application PUBLIC
"-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN"
"http://java.sun.com/dtd/application_1_3.dtd">
<application>
<display-name>ejbsessionBankEAR</display-name>
<description>Example Session Bean Bank Application</description>
<module>
<web>
<web-uri>ejbsessionBankWAR.war</web-uri>
<context-root>/ejbsessionBankWAR</context-root>
</web>
</module>
<module>
<ejb>ejbsessionBankEJB-1.0.2007.2-SNAPSHOT.jar</ejb>
</module>
v090401 JavaEE EAR 13
EnterpriseJava
Example Project with EAR• ejbsessionBank> jar tf ejbsessionBankEAR/target/ejbsessionBankEAR-1.0.2007.2-SNAPSHOT.ear
META-INF/
META-INF/MANIFEST.MF
ejbsessionBankImpl-1.0.2007.2-SNAPSHOT.jar
ejbsessionBankWAR.war
ejbsessionBankEJB-1.0.2007.2-SNAPSHOT.jar
META-INF/application.xml
• EJB META-INF/MANIFEST.MFManifest-Version: 1.0Archiver-Version: Plexus ArchiverCreated-By: Apache MavenBuilt-By: StaffordJBuild-Jdk: 1.5.0_17Class-Path: commons-logging-1.0.4.jar ejbsessionBankImpl-1.0.2007.2-SNAPSHOT.jar
v090401 JavaEE EAR 14
EnterpriseJava
Example Project with EAR: source tree• ejbsessionBank> tree .
• |-- ejbsessionBankImpl
• ...
• |-- ejbsessionBankEAR
• | |-- pom.xml
• |-- ejbsessionBankEJB
• ...
• |-- ejbsessionBankTest
• ...
• |-- ejbsessionBankWAR
• ...
• |-- pom.xml
v090401 JavaEE EAR 15
EnterpriseJava
Example Project with EAR: root pom.xml<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ejava.javaee.ejb</groupId>
<artifactId>ejbsessionBank</artifactId>
<packaging>pom</packaging>
<name>Session Bean</name>
<version>1.0-SNAPSHOT</version>
<description>
This project is the root project for the core session bean example.
</description>
<modules>
<module>ejbsessionBankImpl</module>
<module>ejbsessionBankEJB</module>
<module>ejbsessionBankWAR</module>
<module>ejbsessionBankEAR</module>
<module>ejbsessionBankTest</module>
</modules>
</project>
v090401 JavaEE EAR 16
EnterpriseJava
Example Project with EAR: ear pom.xml <modelVersion>4.0.0</modelVersion>
<groupId>ejava.javaee.ejb</groupId>
<artifactId>ejbsessionBankEAR</artifactId>
<packaging>ear</packaging>
<name>Session Bank EAR</name>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>ejbsessionBankEJB</artifactId>
<version>${pom.version}</version>
<type>ejb</type>
</dependency>
<dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>ejbsessionBankWAR</artifactId>
<version>${pom.version}</version>
<type>war</type>
</dependency>
</dependencies>
v090401 JavaEE EAR 17
EnterpriseJavaExample Project with EAR: excluding
unwanted dependencies <dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>ejbsessionBankEJB</artifactId>
<version>${pom.version}</version>
<type>ejb</type>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
v090401 JavaEE EAR 18
EnterpriseJava
Example Project with EAR: ear plugin <build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<description>
Example Session Bean Bank Application
</description>
<modules>
<webModule>
<groupId>${pom.groupId}</groupId>
<artifactId>ejbsessionBankWAR</artifactId>
<contextRoot>ejbsessionbank</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
v090401 JavaEE EAR 19
EnterpriseJava
Example EAR Project: build output
> tree.|-- pom.xml`-- target |-- application.xml |-- ejbsessionBankEAR-1.0.2007.2-SNAPSHOT | |-- META-INF | | `-- application.xml | |-- ejbsessionBankImpl-1.0.2007.2-SNAPSHOT.jar | |-- ejbsessionBankEJB-1.0.2007.2-SNAPSHOT.jar | `-- ejbsessionBankWAR-1.0.2007.2-SNAPSHOT.war `-- ejbsessionBankEAR-1.0.2007.2-SNAPSHOT.ear
v090401 JavaEE EAR 20
EnterpriseJavaExample EAR Project: deploying EAR
with cargo (Test/pom.xml)<plugin> <groupId>org.codehaus.cargo</groupId> <artifactId>cargo-maven2-plugin</artifactId> <configuration> <container> <containerId>jboss4x</containerId> <type>remote</type> </container> </configuration> <executions> <execution>... </execution> </executions></plugin>
v090401 JavaEE EAR 21
EnterpriseJavaExample EAR Project: deploying EAR
with cargo (Test/pom.xml) <execution> <id>deploy-component</id> <!-- jump into a phase before surefire runs tests --> <phase>test-compile</phase> <goals> <goal>undeploy</goal> <goal>deploy</goal> </goals> <configuration> <configuration> <type>runtime</type> <properties> <cargo.remote.username>${jboss.user}</cargo.remote.username> <cargo.remote.password>${jboss.password}</cargo.remote.password> </properties> </configuration>...
v090401 JavaEE EAR 22
EnterpriseJavaExample EAR Project: deploying EAR
with cargo (Test/pom.xml)... <deployer> <type>remote</type> <deployables> <deployable> <groupId>${pom.groupId}</groupId> <artifactId>ejbsessionBankEAR</artifactId> <type>ear</type> </deployable> </deployables> </deployer> </configuration> </execution>
v090401 JavaEE EAR 23
EnterpriseJavaExample EAR Project: deploying EAR
with cargo (Test project output)• Test output[INFO] Building Session Bank Test[INFO] task-segment: [install][INFO] ----------------------------------------------------------------------------...[INFO] [cargo:undeploy {execution: deploy-component}][INFO] [cargo:deploy {execution: deploy-component}]
• Server Console23:38:50,173 INFO [EARDeployer] Undeploying J2EE application, destroy step:
file:/home/jcstaff/proj/ejava-javaee/working/ejbsessionBank/ejbsessionBankEAR/target/ejbsessionBankEAR-1.0.2007.2-SNAPSHOT.ear
23:38:50,174 INFO [EARDeployer] Undeployed J2EE application: file:/home/jcstaff/proj/ejava-javaee/working/ejbsessionBank/ejbsessionBankEAR/target/ejbsessionBankEAR-1.0.2007.2-SNAPSHOT.ear
23:38:50,272 INFO [EARDeployer] Init J2EE application: file:/home/jcstaff/proj/ejava-javaee/working/ejbsessionBank/ejbsessionBankEAR/target/ejbsessionBankEAR-1.0.2007.2-SNAPSHOT.ear
v090401 JavaEE EAR 24
EnterpriseJavaExample EAR Project: undeploying EAR
with cargo (EAR/pom.xml)<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<container>
<containerId>jboss4x</containerId>
<type>remote</type>
</container>
</configuration>
<executions>
<execution>
<id>undeploy-ear</id>
<phase>pre-clean</phase>
<goals>
<goal>undeploy</goal>
</goals>
<configuration>
<configuration>
<type>runtime</type>
...
v090401 JavaEE EAR 25
EnterpriseJavaExample EAR Project: undeploying EAR
with cargo (EAR/pom.xml)...
<properties>
<cargo.remote.username>${jboss.user}</cargo.remote.username>
<cargo.remote.password>${jboss.password}</cargo.remote.password>
</properties>
</configuration>
<deployer>
<type>remote</type>
<deployables>
<deployable>
<groupId>${pom.groupId}</groupId>
<artifactId>${pom.artifactId}</artifactId>
<type>ear</type>
</deployable>
</deployables>
</deployer>
</configuration>
</execution>
</executions>
</plugin>
v090401 JavaEE EAR 26
EnterpriseJavaExample EAR Project: undeploying EAR
with cargo (EAR project output)• Build output> mvn clean -Pundeploy...[INFO] Building Session Bank EAR[INFO] task-segment: [clean][INFO] ----------------------------------------------------------------------------[INFO] [cargo:undeploy {execution: undeploy-ear}][INFO] [clean:clean]...
• Server console23:48:58,499 INFO [EARDeployer] Undeploying J2EE application, destroy step:
file:/home/jcstaff/proj/ejava-javaee/working/ejbsessionBank/ejbsessionBankEAR/target/ejbsessionBankEAR-1.0.2007.2-SNAPSHOT.ear
23:48:58,500 INFO [EARDeployer] Undeployed J2EE application: file:/home/jcstaff/proj/ejava-javaee/working/ejbsessionBank/ejbsessionBankEAR/target/ejbsessionBankEAR-1.0.2007.2-SNAPSHOT.ear
v090401 JavaEE EAR 27
EnterpriseJava
Summary
• EARs provide a standard deployment package to the application server
• Application server class loader(s) are designed to provide efficient sharing of resources defined within the EAR
• EAR is a deployment package, cannot be unit tested– requires deployment– requires functional testing that incorporates application server