- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
IMain classloader
Fri, 2011-12-09, 15:23
Hi all
I've been trying to integrate a scala interpreter into an application
running in OSGi.
I have a bundle that will crean an IMain instance and I'd like to use
all classes I have access in the local Runner class but after many
attempts I have failed to do so
I'm using the following code:
val settings = new Settings()
settings.embeddedDefaults(classOf[Runner].getClassLoader)
val i = new IMain(settings) {
override protected def parentClassLoader: ClassLoader =
classOf[Runner].getClassLoader
}
i.setContextClassLoader()
i.addImports("edu.gemini.aspen.giapi.status.StatusItem")
However the import fails with:
[packageobjects in 0ms]
:7: error: not found: value edu
import edu.gemini.aspen.giapi.status
^
Notice that if I do
println(classOf[Runner].getClassLoader.loadClass("edu.gemini.aspen.giapi.status.StatusItem"))
That works fine
So, it seems IMain is not delegating to the parentClassLoader.
Is there some way to force IMain to use the given classloader?
Regards
Carlos
Fri, 2011-12-09, 20:31
#2
Re: IMain classloader
Hi Aleksey
I tried that as you can see in the code below. Did you also try that in OSGi?
Carlos
On Dec 9, 2011, at 4:02 PM, Aleksey Nikiforov wrote:
I tried that as you can see in the code below. Did you also try that in OSGi?
Carlos
On Dec 9, 2011, at 4:02 PM, Aleksey Nikiforov wrote:
I have had this issue recently. The solution that worked for me was:
val imain = new IMain(settings, flusher) {
override protected def parentClassLoader: ClassLoader = this.getClass.getClassLoader()
}
You can put whatever classloader you want instead of this.getClass.getClassLoader.
On Fri, Dec 9, 2011 at 8:23 AM, cquiroz <carlos.m.quiroz@gmail.com> wrote:
Hi all
I've been trying to integrate a scala interpreter into an application
running in OSGi.
I have a bundle that will crean an IMain instance and I'd like to use
all classes I have access in the local Runner class but after many
attempts I have failed to do so
I'm using the following code:
val settings = new Settings()
settings.embeddedDefaults(classOf[Runner].getClassLoader)
val i = new IMain(settings) {
override protected def parentClassLoader: ClassLoader =
classOf[Runner].getClassLoader
}
i.setContextClassLoader()
i.addImports("edu.gemini.aspen.giapi.status.StatusItem")
However the import fails with:
[packageobjects in 0ms]
<console>:7: error: not found: value edu
import edu.gemini.aspen.giapi.status
^
Notice that if I do
println(classOf[Runner].getClassLoader.loadClass("edu.gemini.aspen.giapi.status.StatusItem"))
That works fine
So, it seems IMain is not delegating to the parentClassLoader.
Is there some way to force IMain to use the given classloader?
Regards
Carlos
Fri, 2011-12-09, 22:11
#3
Re: IMain classloader
In order for the interpreter to see classes they must be specified on the interpreter classpath. You must specify the classpath using an instance of Settings that configures the interpreter. Classloader comes in play much later, after the classes have been compiled.
On Fri, Dec 9, 2011 at 1:25 PM, Carlos Quiroz <carlos.m.quiroz@gmail.com> wrote:
On Fri, Dec 9, 2011 at 1:25 PM, Carlos Quiroz <carlos.m.quiroz@gmail.com> wrote:
Hi Aleksey
I tried that as you can see in the code below. Did you also try that in OSGi?
Carlos
Sat, 2011-12-10, 03:41
#4
Re: IMain classloader
Carlos,
Are you trying to load classes from other bundles? If so a
DynamicImport-Package: *
in your manifest might do the trick.
Cheers,
Jon-Erling
On Dec 9, 2011, at 15:23 , cquiroz wrote:
> Hi all
>
> I've been trying to integrate a scala interpreter into an application
> running in OSGi.
> I have a bundle that will crean an IMain instance and I'd like to use
> all classes I have access in the local Runner class but after many
> attempts I have failed to do so
> I'm using the following code:
>
> val settings = new Settings()
> settings.embeddedDefaults(classOf[Runner].getClassLoader)
>
> val i = new IMain(settings) {
> override protected def parentClassLoader: ClassLoader =
> classOf[Runner].getClassLoader
> }
> i.setContextClassLoader()
> i.addImports("edu.gemini.aspen.giapi.status.StatusItem")
>
> However the import fails with:
> [packageobjects in 0ms]
> :7: error: not found: value edu
> import edu.gemini.aspen.giapi.status
> ^
>
> Notice that if I do
>
> println(classOf[Runner].getClassLoader.loadClass("edu.gemini.aspen.giapi.status.StatusItem"))
> That works fine
>
> So, it seems IMain is not delegating to the parentClassLoader.
> Is there some way to force IMain to use the given classloader?
>
> Regards
> Carlos
val imain = new IMain(settings, flusher) {
override protected def parentClassLoader: ClassLoader = this.getClass.getClassLoader()
}
You can put whatever classloader you want instead of this.getClass.getClassLoader.
On Fri, Dec 9, 2011 at 8:23 AM, cquiroz <carlos.m.quiroz@gmail.com> wrote: