• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Class loading problem

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a standard ant task.Why do you want to rewrite it ?
 
reply
    Bookmark Topic Watch Topic
  • New Topic