270 likes | 347 Views
Java EE Enterprise Archive (EAR). Goals. Understand the purpose for an EAR Be able to construct an EAR for developed Java EE components. Objectives. EAR Purpose EAR Format. Class Loaders. Arranged in a parent/child relationship
E N D
Java EE Enterprise Archive (EAR) JavaEE EAR
JavaEE EAR Goals Understand the purpose for an EAR Be able to construct an EAR for developed Java EE components
JavaEE EAR Objectives EAR Purpose EAR Format
JavaEE EAR 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
JavaEE EAR 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 Application Server Class Loader EJB App Class Loader Web App Class Loader Web App Class Loader
JavaEE EAR J2EE Enterprise Application Deployment Application Server Class Loader EAR Class Loader EJB interfaces and dependent classes identified by EJB manifests loaded by EAR’s classloader EAR Class Loader • 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 App Class Loader Web App 2 Class Loader Web App 1 Class Loader Servlets/JSPs and lib.jars loaded by isolated classloaders
Enterprise Application Archive (EAR) EAR WAR EJB WAR EJB WAR EJB Utility Classes Utility Classes Utility Classes Resource Adapter Client App Client App Resource Adapter Client App Resource Adapter META-INF/application.xml • 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 JavaEE EAR
JavaEE EAR 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
JavaEE EAR application.xml application icon display-name description? module+ security-role* small-icon large-icon description? ejb|connector|java|web alt-dd role-name web-uri context-root
JavaEE EAR 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
JavaEE EAR 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
JavaEE EAR 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>
JavaEE EAR 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.MF Manifest-Version: 1.0 Archiver-Version: Plexus Archiver Created-By: Apache Maven Built-By: StaffordJ Build-Jdk: 1.5.0_17 Class-Path: commons-logging-1.0.4.jar ejbsessionBankImpl-1.0.2007.2-SNAPSHOT.jar
JavaEE EAR Example Project with EAR: source tree ejbsessionBank> tree . |-- ejbsessionBankImpl ... |-- ejbsessionBankEAR | |-- pom.xml |-- ejbsessionBankEJB ... |-- ejbsessionBankTest ... |-- ejbsessionBankWAR ... |-- pom.xml
JavaEE EAR 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>
JavaEE EAR 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>
JavaEE EAR Example 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>
JavaEE EAR 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>
JavaEE EAR 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
JavaEE EAR Example 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>
JavaEE EAR Example 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> ...
JavaEE EAR Example 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>
JavaEE EAR Example 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 Console 23: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
JavaEE EAR Example 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> ...
JavaEE EAR Example 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>
JavaEE EAR Example 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 console 23: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
JavaEE EAR 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