Class loading problem

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 is compiled succesfully.

After that when I am tring 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 writng custom implementation of findClass() method in ReproClassLoader and Inside of the findClass()

the class loader fetches the byte codes from loacl 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

[1999 byte] By [sabya125a] at [2007-11-26 22:47:03]
# 1

Hi Sabya,

1)I have no clue about this error of yours, but the JspTemplate says that may be you are including the jsp files to be compiled as well. Check that out. If you wish to compile jsp's in ant, u gotta use jspc instead of javac. I have never compiled jsps in ant taks, just war/jar them and deploy them. Your servlet container will do the rest. Why dont you try and write a script and check ?

2) I was reading your earler posts about JMS. Didnt think it would be right to post there, cos I thot you wudnt be checking them anyway. I am in the same position now. I am using Spring+JMS+MDB. Gotta fit in Websphere MQ in this equation as well. I did a lot of readin in these last two days and now I am aware of what MQ is and what JMS is.

I was wondering if you had the time enough and could explain me what the flow is like and what exactly is happening around here. Even if you can post back links which point to this information, it d be great

thanks

Sarvanandaa at 2007-7-10 12:05:43 > top of Java-index,Desktop,Runtime Environment...