Thank you for the reply Peter.
I think you are right, it has got something to do with the classloader.
What i did next was, i printed out the classloader being used, so i put following line in my Tester.java
When i run the build.xml (the one i modified to get successfull output!), it prints the classloader as :-
This means, the Sun Microsystem's VM's Classloader is not used. Immediately what i did next was, i ran the same program as a java command,
instead of running it as an ant task. So i executed the program as: -
When i do so, ... the program runs properly without any exception. The classloader displayed at this time is of Sun !
This time, when Tester was executed, as no exception was reported, that means, the Sun's classloader was able to find, necessary Log4j related classes
by looking into the CLASSPATH environment variable! (I found this by printing out the "java.class.path" system property and in case of Sun's classloader, it prints out my CLASSPATH environment variables, and in case of ANTCLASSLOADER, it prints the location where ONLY all the ant related jar files are present!)
... so i went a STEP further to understand the working of ANT.
I created another execute target in the build.xml, But this time i marked the "
fork" attribute of this new target as "
true" the build.xml looks as follows: -
I did this, so that instead of Ant's classloader .... the Sun's classloader is used, and that the log4j jar file will be picked up from the CLASSPATH directly.
In other words, i was expecting that "
executeProject3" will run as if i ran the Tester class using the ordinary java command and that the program will run
successfully.
But i got the same exception as i got earlier of NoClassDefFound for the Logger class !
But surprisingly, although this time, the Sun's classloader is used, the CLASSPATH environment variable is not refered,
... even the system property "
java.class.path" prints, the location that Ant class loader used to refer to !
Therefore, obviously, the program fails to execute.
Can someone please tell me, what happens when ANT is run, which paths are looked into, when and by which class loaders ?
Although, this is interesting....it is also confusing !
Thanks and Regards
Omkar Patkar