Return-Path: Delivered-To: apmail-ant-user-archive@www.apache.org Received: (qmail 4939 invoked from network); 22 Sep 2005 09:38:24 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 22 Sep 2005 09:38:24 -0000 Received: (qmail 12144 invoked by uid 500); 22 Sep 2005 09:38:17 -0000 Delivered-To: apmail-ant-user-archive@ant.apache.org Received: (qmail 12102 invoked by uid 500); 22 Sep 2005 09:38:16 -0000 Mailing-List: contact user-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Ant Users List" Reply-To: "Ant Users List" Delivered-To: mailing list user@ant.apache.org Received: (qmail 12089 invoked by uid 99); 22 Sep 2005 09:38:16 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Sep 2005 02:38:16 -0700 X-ASF-Spam-Status: No, hits=0.5 required=10.0 tests=HTML_20_30,HTML_MESSAGE,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of jmclennan@clear2pay.com designates 213.246.195.4 as permitted sender) Received: from [213.246.195.4] (HELO hermes.clear2pay.com) (213.246.195.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Sep 2005 02:38:23 -0700 Received: from [192.168.244.167] ([192.168.244.167]) by hermes.clear2pay.com with Microsoft SMTPSVC(6.0.3790.1830); Thu, 22 Sep 2005 11:37:51 +0200 Message-ID: <43327B6F.7060707@clear2pay.com> Date: Thu, 22 Sep 2005 11:37:51 +0200 From: Jon McLennan User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 To: user@ant.apache.org Subject: NoClassDefFoundError when loading class from -lib Content-Type: multipart/alternative; boundary="------------030303040908050401010900" X-OriginalArrivalTime: 22 Sep 2005 09:37:51.0990 (UTC) FILETIME=[4D4E5160:01C5BF59] X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N --------------030303040908050401010900 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit I've taken the source for org.apache.tools.ant.Launcher and modified it to call my own version of Main.java. 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 org.apache.tools.ant.Main.) 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 Main.java I get this error: java.lang.NoClassDefFoundError: org/apache/log4j/Category at java.lang.Class.newInstance0(Native Method) at java.lang.Class.newInstance(Class.java:232) at com.clear2pay.releng.Launcher.run(Launcher.java:351) at com.clear2pay.releng.Launcher.main(Launcher.java:75) I'm running Ant 1.6.1 (installed at D:\java\ant-1.6.1) and the 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:\java\lib\releng.jar; d:\java\apache-ant-1.6.1\lib\ant.jar; d:\java\apache-ant-1.6.1\lib\ant-launcher.jar; d:\java\apache-ant-1.6.1\lib\xml-apis.jar; d:\bea\jdk131\jre\lib\rt.jar; d:\bea\jdk131\lib\dt.jar; d:\bea\jdk131\lib\tools.jar; 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. Jon --------------030303040908050401010900--