Scalate in OSGI environment

91 views
Skip to first unread message

Zeus Sphinx

unread,
Aug 24, 2010, 11:13:53 AM8/24/10
to sca...@googlegroups.com
Hi all,

I am trying to use scalate (1.3-SNAPSHOT) in an OSGI environment based on apache aries. So far it is unable to compile templates with the exception "object scala not found." Any ideas on why this is or anything I have to take into consideration when using it in an OSGI environment. I have made available scala-compiler.jar and scala-library.jar as osgi bundles exporting all packages.

Thanks

~zs



James Strachan

unread,
Aug 24, 2010, 11:22:53 AM8/24/10
to sca...@googlegroups.com

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/

Zeus Sphinx

unread,
Aug 24, 2010, 11:29:29 AM8/24/10
to sca...@googlegroups.com
Dear James,

Thank you so much for your reply. I'd try and have a play at this and let you know if I find any luck.

Thanks again,
~zs
~zs



James Strachan

unread,
Aug 24, 2010, 11:55:19 AM8/24/10
to sca...@googlegroups.com
After a quick google I found this thread btw...
http://scala-programming-language.1934581.n4.nabble.com/How-to-compile-Scala-code-from-java-using-the-current-ClassLoader-instead-of-a-string-based-classpat-td1955873.html

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! :)

James Strachan

unread,
Aug 24, 2010, 11:59:53 AM8/24/10
to sca...@googlegroups.com
On 24 August 2010 16:55, James Strachan <james.s...@gmail.com> wrote:
> After a quick google I found this thread btw...
> http://scala-programming-language.1934581.n4.nabble.com/How-to-compile-Scala-code-from-java-using-the-current-ClassLoader-instead-of-a-string-based-classpat-td1955873.html
>
> 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...

https://svn.apache.org/repos/asf/sling/trunk/contrib/scripting/scala/script/src/main/scala/org/apache/sling/scripting/scala/BundleFS.scala

wow - wacky stuff! :)

Heiko Seeberger

unread,
Aug 24, 2010, 4:38:47 PM8/24/10
to sca...@googlegroups.com
James, Zeus,

Probably James is right and this will be a little painful. But maybe there is a chance that the OSGi-fied Scala JARs of scala-lang-osgi (http://wiki.github.com/weiglewilczek/scala-lang-osgi/) will do the job. They did it once in another framework that did compilation at runtime.

Zeus, would you mind giving it a try? Just install the scala-lang.jar and scala-compiler.jar from scala-lang-osgi into your OSGi container.

Heiko
--
Heiko Seeberger

Company: weiglewilczek.com
Blog: heikoseeberger.name
Follow me: twitter.com/hseeberger
OSGi on Scala: scalamodules.org
Lift, the simply functional web framework: liftweb.net
Stambecco, highly scalable computing: stambecco.org
Akka - Simpler Scalability, Fault-Tolerance, Concurrency & Remoting through Actors: akkasource.org

James Strachan

unread,
Aug 24, 2010, 10:05:40 PM8/24/10
to sca...@googlegroups.com
On 24 August 2010 21:38, Heiko Seeberger <heiko.s...@googlemail.com> wrote:
> James, Zeus,
> Probably James is right and this will be a little painful. But maybe there
> is a chance that the OSGi-fied Scala JARs of scala-lang-osgi
> (http://wiki.github.com/weiglewilczek/scala-lang-osgi/) will do the job.
> They did it once in another framework that did compilation at runtime.
> Zeus, would you mind giving it a try? Just install the scala-lang.jar and
> scala-compiler.jar from scala-lang-osgi into your OSGi container.
> Heiko

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?

Heiko Seeberger

unread,
Aug 25, 2010, 1:24:46 AM8/25/10
to sca...@googlegroups.com
Hi James,

On the long run we need a clean way of dealing with the issue. I didn't know the Sling approach, but will take a look.
Meanwhile there is some "dirty magic" called DynamicImport-Package ;-) Don't you think that will do the job?

Heiko

James Strachan

unread,
Aug 25, 2010, 3:41:24 AM8/25/10
to sca...@googlegroups.com
On 25 August 2010 06:24, Heiko Seeberger <heiko.s...@googlemail.com> wrote:
> Hi James,
> On the long run we need a clean way of dealing with the issue. I didn't know
> the Sling approach, but will take a look.
> Meanwhile there is some "dirty magic" called DynamicImport-Package ;-) Don't
> you think that will do the job?

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

Zeus Sphinx

unread,
Aug 29, 2010, 8:31:44 AM8/29/10
to sca...@googlegroups.com
Heiko,

I was already using those JARs. It initially complained of the missing jline.jar and msil.jar, but everthing else went fine. It was just the template compilation that was the problem.

Cheers,
~zs



Heiko Seeberger

unread,
Aug 31, 2010, 2:25:23 PM8/31/10
to sca...@googlegroups.com
Zeus,

Bad news and good news. Could you perhaps send me your setup? I am interested in fixing this complaining about missing jline.jar and msil.jar.

Heiko

Zeus Sphinx

unread,
Aug 29, 2010, 8:28:58 AM8/29/10
to sca...@googlegroups.com
Hi guys,

Apologies, I've been away in a very very remote place. I am just seeing your messages. I will look at the ideas and let you know if I get some luck.

Thanks,
~zs
~zs



Reply all
Reply to author
Forward
0 new messages