Inside Scoop on J2EE : Tips and tricks on J2EE and Oracle Application Server by Debu Panda
Updated: 11/18/2004; 5:19:52 PM.

 

Subscribe to "Inside Scoop on J2EE" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.

 
 

Monday, June 07, 2004

 

Here are some common classloading best practices that we have been following and hope useful to many.

 

  • Declare dependencies. Make dependencies explicit. Hidden or unknown dependencies will be left behind when you move your application to another environment. Specify the dependencies in the Manifest Class-Path entry of EJB-JAR or WAR file on the libraries packaged in the same application.
  • Group dependencies. Ensure that all dependencies are visible at the same level or above. If you must move a library, make sure all dependencies are still visible.
  • Minimize visibility. Dependency libraries should be placed at the lowest visibility level that satisfies all dependencies.
  • Share libraries. Avoid duplicating libraries. Duplication of libraries may make  debugging classloading issues a nightmare. Share classes across a set of applications by using the configuration facilities provided by your application server. For example, use the <library> tag in the global application.xml file in OC4J to share classes across all applications.
  • Keep configurations portable. Choose configuration options in the following order:
    • Standard J2EE options
    • Options that can be expressed within your EAR file
    • Server-level options
    • J2SE extension options
  • Use the correct loader. If you call Class.forName(), always explicitly pass the loader returned by Thread.currentThread().getContextClassLoader. If you are loading a properties file, use Thread.currentThread().getContextClassLoader().getResourceAsStream().
  • Avoid hardcoding of a specific parser in your application. Use JAXP API to access the underlying XML/XSL parsers in a vendor-neutral way instead of hard coding a specific XML parser in your application.
  • Avoid hot redeployment. Hot deployment depends upon classloaders and hot (re)depployment may introduce classloading errors. Avoid hot deployment if there is to much dependencies between applications and external libraries.

For details on Classloading in J2EE please take a look at the Classloading technical paper in OTN.


11:20:09 AM    comment []

© Copyright 2004 Debu Panda.

PS: These are my own thoughts and not of my employer ..



Click here to visit the Radio UserLand website.
 


June 2004
Sun Mon Tue Wed Thu Fri Sat
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30      
May   Jul