ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sabyasachi Sahu" <sahu.sabyasa...@gmail.com>
Subject Class loading problem
Date Sat, 24 Mar 2007 11:31:41 GMT
Hi,

I am creating ant task "Javac" to compile a java file generated at runtime
using *ant-1.6.5.jar*

A sample code snippet is as follows:-



Javac javac = new Javac();

javac.setProject (ANT_PROJECT);



Path path = new Path (ANT_PROJECT);

path.setPath (libdirPath_); // dependency jar needed for compilation of the
generated java file.

......

javac.init ();

javac.setTarget ("1.5");

javac.setIncludejavaruntime (true);

javac.setDestdir (m_options.getClassesDir ());

javac.setEncoding (pnode.getEncoding ());

javac.setClasspath (path);

javac.setDebug (true);

javac.setSrcdir (srcPath);

javac.setOptimize (false);



try {

 log. debug ("Compiling java source." + getJavaFile().getAbsolutePath());

 javac.execute ();

 log.debug ("Compiled java source.");

 }



 catch (BuildException e) {

 }

 *Java file is compiled succesfully*.

 After that when I am trying to load the class using custom class loader in
the following way:

 private _JspTemplate tpl;

 .....

 ReproClassLoader loader = (ReproClassLoader)
Thread.currentThread().getContextClassLoader ();

 Class clazz = loader.loadClass (classQualified);

 tpl = (_JspTemplate) clazz.newInstance ();



 getting an NoClassDefFoundError.. com.anshinsoft.repro.jsp._JspTemplate



 _JspTemplate is an abstract class and the generated java file is subclass
of _JspTemplate.

 My custom class loader "ReproClassLoader" basically URLClassLoader is used
to load jar files at runtime.



 when I am writing custom implementation of findClass () method in
ReproClassLoader and Inside of the findClass ()

 the class loader fetches the byte codes from local file system, then it is
succesfully executed.

 My concern is whether this is the only solution or not?

 Can I do it in a better way? Please suggest.

 Any help is highly appreciated



 Thanks and Regards,

 Sabyasachi

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message