- Get Log4j: Download Apache log4j from http://logging.apache.org/log4j/. Apache log4j has three development branches: a stable branch, 1.2; a discontinued branch, 1.3; and an experimental branch, 2.0.
- Setup: Unzip the file in the dedicated directory. log4j-x.y.z.jar should be in log4j directory.
- Use Log4j: There are two examples in log4j directory:
- Trivial.java for a trivial usage example.
- Sort.java and SortAlgo.java to for a slightly more advanced example.
Right click the project in Package Explorer. Then click Properties > Java Build Path > Libraries > Add External JARs...
Now we add Main.java and Trivial.java classes: In Main.java:public class Main { public static void main(String[] args) { Trivial.run(args); } }
In Trivial.java, we change main() method's name to run(). Run: Trivial class should output four lines. - Trivial.java for a trivial usage example.
2011年8月29日 星期一
[Java] Using Log4j in Eclipse
Step by step:
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言