Your SlideShare is downloading. ×
  • Like
  • Save
Designing JEE Application Structure
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Designing JEE Application Structure

  • 15,606 views
Published

We will learn how to correctly design JEE applications modules. …

We will learn how to correctly design JEE applications modules.
How to design module dependencies.
JEE class loaders

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
  • Thanks I appreciate it.
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
15,606
On SlideShare
0
From Embeds
0
Number of Embeds
3

Actions

Shares
Downloads
0
Comments
1
Likes
20

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Designing JEE Application Structure Oded Nissan
  • 2. Motivation
    • Designing JEE applications structure could be a complex task.
    • We will learn how to correctly design JEE applications modules.
    • How to design module dependencies.
    • In order to do that we need to understand about JEE modules, their structure and about JEE class loading.
    Copyright (c) Oded Nissan 2010
  • 3. Agenda
    • JEE Modules and applications
    • JEE application structure
    • Java class loading basics
    • JEE class loaders.
    • Class loading scenarios
    • Designing JEE application structure
    • Designing module dependencies
    Copyright (c) Oded Nissan 2010
  • 4. JEE Modules
    • Web module – contains a web application. (JSP, servlets, web services).
    • EJB module – contains one or more EJBs.
    • Resource Adapter – a Software service that connects to an external system.
    • Application Client – Java clients that use JEE resources.
    • Utility module – java code packaged as a jar file.
    Copyright (c) Oded Nissan 2010
  • 5. JEE Application Copyright (c) Oded Nissan 2010
  • 6. JEE Application Structure Copyright (c) Oded Nissan 2010
  • 7. JEE Application Structure
    • A JEE application is packaged into an EAR file.
    • The EAR file contains Web modules, EJB modules and utility jars.
    • The Web application is packaged into a WAR file, and the WAR file is packaged into the EAR.
    • The EJB’s are packaged into a special jar file which is the EJB module, which is packaged into the EAR file.
    • 3 rd party jars can be put into the EAR’s lib directory or root directory.
    Copyright (c) Oded Nissan 2010
  • 8. The EAR File Structure Copyright (c) Oded Nissan 2010
  • 9. Java Class Loaders
    • Class loaders enable the Java virtual machine (JVM) to load classes. Given the name of a class, the class loader locates the definition of this class.
    • Each Java class must be loaded by a class loader.
    • The JVM uses more than one class loader. Class loaders are organized in a hierarchy
    Copyright (c) Oded Nissan 2010
  • 10. Important Note
    • We need to differentiate between compile-time and runtime class loading.
    • The compiler uses compile-time class loading to resolve classes for compilation.
    • The application or application server uses runtime class loading to resolve classes when the application executes.
    • Compile-time and runtime class loading may not be identical.
    Copyright (c) Oded Nissan 2010
  • 11. Java Class Loaders
    • By default the JVM uses three class loaders:
      • bootstrap class loader loads the core Java libraries
      • extensions class loader loads extention java libraries
      • application class loader loads classes from the CLASSPATH.
    Copyright (c) Oded Nissan 2010
  • 12. Java Class Loaders
    • A class loader delegates class loading to its parent before trying to load the class itself. The parent class loader can be either another custom class loader or the bootstrap class loader.
    • A class loader can only delegate requests to its parent class loader, never to its child class loaders (it can go up the hierarchy but never down).
    Copyright (c) Oded Nissan 2010
  • 13. The JVM ClassLoader Hierarchy Copyright (c) Oded Nissan 2010
  • 14. Java Class Loading
    • The runtime identity of a class in Java is defined by the fully qualified class name and its defining class loader .
    • This means that the same class, loaded by two different class loaders, is seen by the Virtual Machine as two completely different types.
    Copyright (c) Oded Nissan 2010
  • 15. Class Loader Visibility
    • Which class is visible to the class loader ?
    • A class loader has visibility to classes that it loaded or classes that were loader by class loaders higher in the hierarchy.
    • There is not top-down visibility among class loaders.
    • Class loaders at the same hierarchy level are invisible to each other.
    Copyright (c) Oded Nissan 2010
  • 16. WebSphere Class Loaders
    • The WAS extension class loader - The class path used by the extensions class loader is retrieved from the ws.ext.dirs system property.
    • Web Module class loader – loads classes from the WEB-INF/classes WEB-INF/lib directories in the web application.
    • Application class loader – handles EJB modules utility jars etc that reside in the EAR file.
    Copyright (c) Oded Nissan 2010
  • 17. The WebSphere Class Loader Hierarchy Copyright (c) Oded Nissan 2010
  • 18. WebSphere Class Loader Policies
    • Single - a single application loader is used to load all EJBs, utility JARs, and shared libraries. Same with single web class loader.
    • Multiple – each application (or web application) will receive its own class loader.
    Copyright (c) Oded Nissan 2010
  • 19. Multiple Class Loaders
    • Total isolation between applications and web modules.
    Copyright (c) Oded Nissan 2010
  • 20. Single Web class loader
    • WAR2-2 is loaded by the application class loader.
    Copyright (c) Oded Nissan 2010
  • 21. Single Application class loader
    • Single application class loader and single web class loader for WAR2.
    Copyright (c) Oded Nissan 2010
  • 22. Class loading order
    • Parent first – first try to load classes using the parent class loader. This is the default. (JVM behavior).
    • Application first (parent last) – try to load classes using the application’s class loader (web or application) before delegating to the parent. This allows the application to override classes in the parent.
    Copyright (c) Oded Nissan 2010
  • 23. Shared Libraries
    • These are libraries that we want to share among all applications. For example: framework libraries.
    • Shared libraries are defined using the administration tools. They consist of a symbolic name, a Java class path, and a native path for loading JNI libraries.
    • Share libraries need to be associated with an application in order to be loaded.
    Copyright (c) Oded Nissan 2010
  • 24. JBoss Class Loading
    • JBoss uses the concept of a loader repository to prevent class loading conflicts between the applications’ class loaders and other class loaders.
    • The application prefers classes loaded by its class loaders to the same classes loaded by other applications or the server.
    • Loader repositories can be defined at the EAR or WAR level in jboss specific configuration files.
    Copyright (c) Oded Nissan 2010
  • 25. JBoss Class Loading Copyright (c) Oded Nissan 2010
  • 26. Class Loading Pitfalls
    • Loading the same class by two different class loaders can cause a ClassCastException.
    • NoClassDefFoundException means that the class was available at compile time, but is not available at runtime.
    • ClassNotFoundException means the file could not be found by all classloaders, or cannot be found by the visible classloaders in the hierarchy.
    Copyright (c) Oded Nissan 2010
  • 27. Defining projects using eclipse
    • Eclipse Demo.
    Copyright (c) Oded Nissan 2010
  • 28. Packaging Guidelines
    • If your application uses both EJBs and Web Modules, package them in an EAR file. Package 3 rd party jars and utility modules in the EAR.
    • If you have a standalone Web application, package your 3 rd party jars into the WEB-INF/lib directory of the web application.
    • Don’t package JDBC drivers with your application. Let the app server manage them.
    Copyright (c) Oded Nissan 2010
  • 29. Packaging JEE Applications Copyright (c) Oded Nissan 2010 Web Module EJB Module
  • 30. Packaging JEE Applications Copyright (c) Oded Nissan 2010 Web Module EJB Module EAR file- Application Class Loader Web Class Loader
  • 31. Packaging JEE Applications Copyright (c) Oded Nissan 2010 Web Module EJB Module 3 rd Party Jar
  • 32. Packaging JEE Applications Copyright (c) Oded Nissan 2010 Web Module EJB Module 3 rd Party Jar EAR file – Application Class Loader Web Class Loader
  • 33. Packaging JEE Applications Copyright (c) Oded Nissan 2010 Web Module EJB Module 3 rd Party Jar
  • 34. Packaging JEE Applications Copyright (c) Oded Nissan 2010 Web Module EJB Module 3 rd Party Jar EAR file – Application Class Loader Web classloader
  • 35. Packaging JEE Applications Copyright (c) Oded Nissan 2010 Web Module EJB Module Java Module
  • 36. Packaging JEE Applications Copyright (c) Oded Nissan 2010 Web Module EJB Module Java Module EAR file – Application Classloader Web Classloader
  • 37. Designing JEE Application Structure
    • Which JEE modules do we need ?
    • Which dependencies do we have ?
    • Which tier does the module belong to ?
    • No need to create multiple Web or EJB modules within the same applications unless they are reusable within other applications.
    Copyright (c) Oded Nissan 2010
  • 38. Module Dependency Tips
    • Try to consolidate your project into as few eclipse projects as possible.
    • Regarding each dependency, ask yourself is it an architectural dependency or an organization dependency ?
    • There is no need to over modulerize
    • A small set of projects with well defined dependencies are easy to manage and maintain.
    Copyright (c) Oded Nissan 2010
  • 39. Designing JEE Application Structure
    • If you still need to work with a large set of JEE projects/modules :
      • Consider using an Artifact repository such as Maven or Ivy.
      • Separate the deployment process for development and integration. We can have a lightweight deployment, where each team get just the modules it needs, full deployment will be performed in the integration environment.
    Copyright (c) Oded Nissan 2010
  • 40. JEE 6 Features - Deployment
    • In EJB 3.1 the EJB module can be packaged within the web module. We have two options:
      • Package an EJB module into a jar and put it into the WEB-INF/lib directory of the web module.
      • Compile the classes into WEB-INF/classes and put the deployment descriptor into META-INF dir in the web module.
    Copyright (c) Oded Nissan 2010
  • 41. JEE 6 Features - Profiles
    • A JEE profile is a configuration that includes a subset of the JEE technologies stack.
    • The applications server vendors can provide implementations of standard JEE profiles, by providing a launch configuration that adheres to the profile.
    • The JEE spec defines mandatory technologies to be included in each profile, the full profiles and some standard profiles such as the web profile.
    Copyright (c) Oded Nissan 2010
  • 42. JEE 6 Features – EJB Lite
    • EJB 3.1 provides a light EJB model that can be bundled within a custom JEE 6 profile.
    • EJB lite is a subset of the full EJB framework.
    • Limitations:
      • No remote invocation.
      • No MDB
      • No Timer Service
      • No web services endpoint.
      • No asynchronous invocation (new 3.1 feature).
    Copyright (c) Oded Nissan 2010
  • 43. Designing JEE Application Structure
    • JEE 6 greatly simplifies the JEE application packaging options.
    • The current trend towards lightweight containers, such as Spring or JEE 6 lightweight EJB also simplifies the applications structure design.
    • Module dependencies are still an important design issue.
    Copyright (c) Oded Nissan 2010
  • 44. Summary
    • What did we discuss ?
      • JEE modules
      • How JEE class loaders work.
      • How to design JEE application structure.
      • How to design module dependencies.
    Copyright (c) Oded Nissan 2010
  • 45. Thank You Questions ?
  • 46. Backup Slides
    • Discussion
    Copyright (c) Oded Nissan 2010