Good Morning!
I have a very simple test class that I am using to debug a class loader issue with log4j. I can compile my class. I put the class in a jar file with a manifest that points to the class with the main method. The log4j .jar file is in the .\lib directory, below the test1.jar file. I have fussed around with different variations of -cp & -classpath, without success. I can not figure out why the runtime environment can not load the org.apache.log4j.Logger class.
What is wrong with the way that I am setting up the runtime environment?
Thank you!
==========================
source:
-----
import org.apache.log4j.Logger;
public class Test1 {
static Logger logger = Logger.getLogger(Test1.class);
public static void main(String[] args) {
System.out.println("Hello World");
}
}
===========================
compilation:
-----
X:\test>javac -classpath .\;.\lib\log4j-1.2.14.jar Test1.java
jar:
-----
X:\test>jar -cvmf .\META-INF\MANIFEST.MF test1.jar .\*.class
added manifest
adding: Test1.class(in = 627) (out= 380)(deflated 39%)
MANIFEST.MF:
-----
Manifest-Version: 1.0
Created-By: 1.5.0_11 (Sun Microsystems Inc.)
Main-Class: Test1
==========================
.\lib:
-----
X:\test>dir .\lib
Volume in drive X is Storage
Volume Serial Number is 5871-E6FF
Directory of X:\test\lib
11/25/2009 10:19 PM <DIR> .
11/25/2009 10:19 PM <DIR> ..
11/25/2009 10:05 AM 367,444 log4j-1.2.14.jar
1 File(s) 367,444 bytes
2 Dir(s) 27,042,570,240 bytes free
X:\test>
run:
-----
X:\test>java -client -classpath .\;.\lib\log4j-1.2.14.jar -jar test1.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
at Test1.<clinit>(Test1.java:6)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 1 more
Could not find the main class: Test1. Program will exit.
X:\test>