Hi,

I was unable to run a jar file which has a log4j package.
Here is my simple java code :

<code>
package example;

import java.io.*;
 
import org.apache.log4j.*;

public class TestLogging {
 
    static Logger logger = Logger.getLogger(TestLogging.class.getName());
    
    public TestLogging () {
        logger.info("In TestLogging");
    }

    public static void main(String args[]) {
        TestLogging tl = new TestLogging();
    }

}
</code>

Then I build a jar file which has the following files :

C:\usr\Java\Misc\TestLogging\deploy>jar tvf TestLogging.jar
     0 Wed Feb 12 09:59:24 GMT 2003 META-INF/
    88 Wed Feb 12 09:59:24 GMT 2003 META-INF/MANIFEST.MF
     0 Wed Feb 12 09:59:22 GMT 2003 example/
  1284 Wed Feb 12 09:59:22 GMT 2003 example/TestLogging.class

and the content of the manifest file is :

Manifest-Version: 1.0
Created-By: Apache Ant 1.5.1
Main-Class: example.TestLogging

Now, if I run that jar file, I got this error :

C:\usr\Java\Misc\TestLogging\deploy>set CLASSPATH=.

C:\usr\Java\Misc\TestLogging\deploy>java -jar -cp
.;C:\Java\Software\jakarta-log4j-1.2.7\dist\lib\log4j-1.2.7.jar;
C:\j2sdkee1.3.1\lib\j2ee.jar TestLogging.jar
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/log4j/Logger
    at example.TestLogging.<clinit>(TestLogging.java:17)

So, I modified the manifest file into this :

Manifest-Version: 1.0
Created-By: Apache Ant 1.5.1
Main-Class: example.TestLogging
Class-Path: log4j-1.2.7.jar

then build and run it again, but the error was different now :

C:\usr\Java\Misc\TestLogging\deploy>set CLASSPATH=.

C:\usr\Java\Misc\TestLogging\deploy>java -jar -cp
.;C:\Java\Software\jakarta-log4j-1.2.7\dist\lib\log4j-1.2.7.jar;
C:\j2sdkee1.3.1\lib\j2ee.jar TestLogging.jar
log4j:WARN No appenders could be found for logger (example.TestLogging).
log4j:WARN Please initialize the log4j system properly.

C:\usr\Java\Misc\TestLogging\deploy>dir
 Volume in drive C has no label.
 Volume Serial Number is 584D-7CB0

 Directory of C:\usr\Java\Misc\TestLogging\deploy

12/02/2003  10:05       <DIR>          .
12/02/2003  10:05       <DIR>          ..
10/02/2003  14:14              350,677 log4j-1.2.7.jar
12/02/2003  10:04                1,324 log4j.properties
12/02/2003  10:04                1,265 TestLogging.jar


The properties file has the following content :
log4j.rootLogger=DEBUG, A1
log4j.appender.A1=org.apache.log4j.lf5.LF5Appender
log4j.appender.A1.MaxNumberOfRecords=1000

The problem remain unchange even when I put log4j-1.2.7.jar in jre/lib/ext directory.
Notice that I included j2ee.jar in the CLASSPATH, as I need in my other package.

Am I missing something ?

Thanks.

Reply via email to