log4j, an open-source API from the Apache Software Foundation, is a simple yet effective solution for enabling logging for Java applications. With log4j, you can include inheritance-based logging, configurable at runtime, without modifying the code base.
This tip explains the configuration and packaging options for log4j for applications that run on Sun Java System Application Server 7 (formerly Sun ONE Application Server 7 and hereinafter called Application Server 7). It contains the following sections: You can add log4j for the applications that run on all the instances of Application Server 7 or for the applications that run on one particular Application Server 7 instance only. Global Configuration Making the log4j API available in the applications that run on all the instances of Application Server 7 involves two major steps:
Specifically, do the following:
Instance-Specific Configuration
In case only the applications that run in a particular instance of Application Server 7 will use log4j, add log4j to the class path of that instance. This approach ensures that log4j is loaded by the Common Classloader and made available to the applications of that instance.
You can include log4j with deployments of enterprise application archives (EARs) or Web application archives (WARs) in many ways. The goal is to ensure that the components that are based on the Java 2 Platform, Enterprise Edition (J2EE platform) in the application, which contain calls to the log4j API, can successfully call that API.
Packaging of WARs
Packaging log4j with a WAR is straightforward. Simply place the log4j JAR in the WAR's Packaging of EARs For a broad leverage of the log4j API across a J2EE application, place the log4j JAR in the root directory of your EAR to allow access by components that are based on Enterprise JavaBeans (EJB), JSP, or Java Servlet technology. For example, suppose you have a EAR that can be extracted as the following:
Copy the log4j JAR to the root of the EAR. The contents of the EAR then become the following:
However, that step alone is not sufficient and, when application components call the log4j API, will result in an error ( Note - You can add as many JAR references to this manifest entry as required by other APIs.
Thanks to the parent-child relationship of the EJB and Web Classloaders in Application Server 7, once you have added the log4j JAR to the For details on the Application Server 7 Classloaders, see the section, "Classloaders" in the Application Server 7 Developer's Guide.
Matthew Litkey is a member of technical staff of Market Development Engineering at Sun. He works with independent software vendors to develop and integrate applications with Sun Java Enterprise System. Matt graduated from Villanova University, where he served as president of the Villanova Association for Computing Machinery (ACM). In his spare time, Matt enjoys composing and performing music and the theatrical arts.
Jay Galvin is a senior member of technical staff of Marketing Development Engineering at Sun. He works with independent software vendors to develop and integrate applications with Sun Java Enterprise System. Marina Sum is a staff writer for Sun Developer Network. She has been writing for Sun for 15 years, mostly in the technical arena. | ||||||||||||
Oracle is reviewing the Sun product roadmap and will provide guidance to customers in accordance with Oracle's standard product communication policies. Any resulting features and timing of release of such features as determined by Oracle's review of roadmaps, are at the sole discretion of Oracle. All product roadmap information, whether communicated by Sun Microsystems or by Oracle, does not represent a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. It is intended for information purposes only, and may not be incorporated into any contract.
|
| ||||||||||||