ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jon McLennan <>
Subject NoClassDefFoundError when loading class from -lib
Date Tue, 27 Sep 2005 07:47:21 GMT
I posted this to the users list, but didn't get any response. Maybe
someone on this list can help.

I've taken the source for and modified it 
to call my own version of Essentially, the only change I made 
with that class is to allow the user to specify which startup class is 
to be run. (The default is the standard My 
version of Main can create menus from targets in the build file (plus 
some other features). I use log4j for logging debugging messages.

The problem I'm running into is when I call this line:

    Class mainClass = Class.forName(classmain, false, loader); 
    // classmain = my

I get this error:

    java.lang.NoClassDefFoundError: org/apache/log4j/Category
            at java.lang.Class.newInstance0(Native Method)
            at java.lang.Class.newInstance(
            at com.clear2pay.releng.Launcher.main(

I'm running Ant 1.6.1 (installed at D:\java\ant-1.6.1) and my external 
lib directory (D:\java\lib) is passed to Ant via the -lib command line 
arg. I have log4j-1.2.6.jar in that directory.

This is the command line I use:

    java !ANT_OPTS! -classpath  
        d:\bea\jdk131\jre\lib\i18n.jar;" com.clear2pay.releng.Launcher
    -lib "D:\java\lib"
    -mc com.clear2pay.releng.Main

I put some debugging statements in com.clear2pay.releng.Launcher to see 
if org.apache.log4j.Category has been loaded by the ClassLoader

    Class myClass = loader.loadClass("org.apache.log4j.Category");
    System.out.println("myClass = " + myClass);

which outputs:

    myClass = class org.apache.log4j.Category

I even tested it by listing the methods available from that class.

So what I don't understand is, why is com.clear2pay.releng.Launcher able 
to find org.apache.log4j.Category when I get it from the loader, but it 
can't be found when I load a class that imports it? I can get this to 
work if I put all external jars I need directly in the Classpath, but 
this can cause problems on Windows if the value of Classpath gets too 
long and I'd like to avoid that.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message