Hi,
Am Dienstag, den 10.06.2008, 23:15 +0530 schrieb janandith jayawardena:
> Hi Felix,
>
> I tried the above but the exception continues.
>
> I did the following ,
>
> ClassLoader c = Thread.currentThread().getContextClassLoader();
> c.loadClass("scala.tools.nsc.Interpreter");
This is expected to throw, as the thread context class loader has not
been modified.
>
> Thread.currentThread().setContextClassLoader(c.getClass().getClassLoader());
c is the context's class loader. getting the classloader of the context
class loader to set the context class loader might not get you what you
want. This is wrong.
>
> I think the scala library is not loading properly.
Given the code, I am not surprised ;-)
The base class from which you want to take the class loader to use as
the thread context class loader must be loaded from the bundle which
contains your scala library.
The correct thing is to modify the try-catch block in youre
ScalaScriptEngine.eval method as follows:
// before the try-catch block add this:
ClassLoader old = Thread.currentThread().getContextClassLoader();
try {
// add this at the beginning of the block
// here "this" is the ScalaScriptEngine instance, whose
// classloader has the scala interpreter library
Thread.currentThread().setContextClassLoader( getClass().getClassLoader() );
.... do the rest of the block ...
} catch .... as before .... {
// add a new finally block to reset the context class loader
} finally {
Thread.currentThread.setContextClassLoader( old );
}
>
> When I do the following in the eval method the interpreter works.
>
> "interpreterSettings.classpath().value_$eq("/home/janandith/.m2/repository/org/scala-lang/scala-library/2.7.1/scala-library-2.7.1.jar")"
This is of course not an option ;-) And should not be needed if setting
the class loader correctly.
Maybe the Thread context class loader need not be set, I cannot tell.
Maybe there is another way of telling the Scala interpreter which class
loader to primarily use. We can of course NOT feed the Scala interpreter
with a class path setting. This won't work.
Regards
Felix