Common Java Cookbook

Edition: 0.19

Download PDF or Read on Scribd

Download Examples (ZIP)

7.9. Depending on Commons Logging

7.9.1. Problem

You need to use Commons Logging to develop a system that works under various logging frameworks, including Sun's logging framework and Apache Log4J.

7.9.2. Solution

To use Commons Logging 1.0.4 in a Maven 2 project, add the following dependency to your project's pom.xml:

Example 7.7. Adding a Dependency on Commons Logging

<dependency>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
      <version>1.0.4</version>
    </dependency>

7.9.3. Discussion

If you are not sure what this means, I'd suggest reading Maven: The Definitive Guide. When you depend on a library in Maven 2, all you need to do is add the dependency groupId, artifactId, and version to your project's dependencies. Once you do this, Maven 2 will download the dependency and make it available on your project's classpath.

Commons Logging was created for developers who need to create components or libraries that may need to operate in environments with different logging frameworks, including Apache Log4J and the built-in logging framework introduced in Java 1.4. Using Commons Logging, a component like Commons BeanUtils or Commons Digester can write log messages to an abstracted Log interface, and Commons Logging can deal with passing these log messages to whichever logging framework is available.

7.9.4. See Also

For more information about Commons Logging, see the Commons Logging project site (http://commons.apache.org/logging).


Creative Commons License
Common Java Cookbook by Tim O'Brien is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 United States License.
Permissions beyond the scope of this license may be available at http://www.discursive.com/books/cjcook/reference/jakartackbk-PREFACE-1.html. Copyright 2009. Common Java Cookbook Chunked HTML Output. Some Rights Reserved.