Monday, July 26, 2004

Jakarta Ant and Reflection Conflict: Power of FORK!!

Problem
 
Have you ever seen java.lang.NoClassDefFoundError: sun.reflect.SerializationConstructorAccessorImpl while running from your application via Ant target.???. ever wondered how come this error when you run an application, but never conflicted while compiling with current set of jar files??..
  You must have speculated reasons like
  •  Java version might be a problem , Hey jdk_14XX is not right lets switch to jdk_13..
  • May be my ant version is not rite or conflicting with jdk version.

The main reason is Ant and its Virtual machine. whenever we write (Compile task) or (Excecution task) we give control to Ant to determine and look for java in its own way,  Java is stringent in Non-Fork mode on classpaths. So in non-fork mode confusion raises for specific reflection classes above.

Solution

All you have to add  fork="true"  (some ppl do it "yes" option too..feel free to experiment:)), to your Ant and tasks,

From above tweak we say use another VM . which means it kicks in class execution in another VM.

tasks will look something like this

><javac srcdir="${src_dir}" fork="true" destdir="${deploy_dir}"><classpath refid="class.path"></javac><java classname="" fork="true"><classpath refid="class.path"></java>








No comments: