As it happens, using Scalate in an OSGi environment is on my radar
soon; so I'll be banging my head on this too shortly.
The issue is really the Scala compiler - it won't let you pass a
ClassLoader to it unfortunately; so we must somehow look inside the
ClassLoader and try figure out what jars are required to setup a
classpath as a List[String] so we can let the Scala compiler find both
Scala itself along with your domain objects etc. To work around this
we've some smelly code here...
http://github.com/scalate/scalate/blob/master/scalate-core/src/main/scala/org/fusesource/scalate/util/ClassPathBuilder.scala#L104
to try guess based on the ClassLoader. AFAIK there's no real OSGi way
of doing this as class loaders in OSGi are insanely complicated (as
each package gets its own class loader so finding the underlying jars
is gonna be hard).
A work around to this is just use something like a WAR in development
mode where the OSGi class loading restrictions don't apply; then
compiling your Scalate templates to bytecode in the build process; so
that when you deploy your web application into OSGi we don't need to
use the Scala compiler.
Its a week or two away when I really start porting some Scalate apps
to OSGi so I'll report back if I find out anything else about using
the Scala compiler in OSGi
--
James
-------
http://macstrac.blogspot.com/
Open Source Integration
http://fusesource.com/
which doesn't look too positive, but then I've found this...
http://people.apache.org/~mduerig/scala4scripting/
http://www.slideshare.net/guest808acd7/scala-for-scriptinh
(e.g. try slide 32)
So it seems they did some file system abstraction above OSGi - sound wacky! :)
e.g. here's the bundle file system which can be passed to the Scala compiler...
wow - wacky stuff! :)
Hi Heiko
I nearly raised an issue on your github project to see if you could
support using the scala compiler OSGi - but wasn't sure if it was too
cheeky so wussed out :). I guess there's 2 separate things,
(i) having the scala-language.jar and scala-compiler.jar as nicely
behaving bundles
(ii) being able to use the Scala compiler to compile against classes
in bundles in the OSGi class loader forest.
You're OSGi-ified bundles definitely solve (i) though am thinking we
need to do something like the Sling guys did and implement a Scala
compiler file system on top of the bundles for (ii) - unless there's
some other magic in scala-lang-osgi?
I don't think how a bundle imports classes is the issue; its how you
get the classes out of OSGi so you can pass them to the Scala compiler
as the Scala compiler expects a classpath as a list of Strings (to
directories or jars) - not as Class objects or as a ClassLoader.
Seems what the Sling guys did - making a virtual file system on top of
bundles - is the best approach I've seen so far (well its also the
only approach I've seen so far :). I've no idea how else to do it -
other than patching the Scala compiler to take ClassLoaders as well as
class paths/file systems