Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7403995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:11:31+00:00 2026-05-29T05:11:31+00:00

I am using a Scala template engine (Scalate) to compile templates at runtime within

  • 0

I am using a Scala template engine (Scalate) to compile templates at runtime within an OSGi environment (Scala 2.9.1). The templates cannot be pre-compiled because they are built dynamically.

In order for this to work, the Scala compiler needs to run within the OSGi environment. However, since the Scala compiler cannot take a classloader as input, this does not work out of the box.

From my research, there appears to be two general solution approaches:

1) A scala compiler plugin (there is one started here but it has not been touched since 2009, and messages on the scala list in 2009 stated it was not ready for production use.

2) Creating a virtual file system on top of the bundle context which could then be used by the Scala compiler. Apparently the Apache sling guys have successfully used this approach on an older version of Scala.

Has anyone gotten Scalate, Scala 2.9.1, and OSGi to work together to dynamically compile templates?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:11:31+00:00Added an answer on May 29, 2026 at 5:11 am

    My team now has Scala compilation and execution working for Scalate within OSGi.

    In general, the ScalaCompiler settings should be provided with a set of AbstractFile objects that correspond to the relevant OSGi bundles. This is supported by Guggla as referenced by @michid. But while Guggla does provide the AbstractFile layer, it does not yet provide any examples or code for how to create the AbstractFile instances in an OSGi environment. Example code to do the latter can be found in the Sling project (the origin of Guggla itself) as well as in the Scalate project (see ScalaCompiler but note our changes to it below).

    We chose the OSGi-ified scala bundles (compiler and library) from the ServiceMix project. See issue SMX-1048 (with patch) on the scala-compiler bundle.

    Our original intent was to get this working in Scalate, and so the rest of this answer is specific to that project.

    The Scalate code already had most of the logic necessary to work within an OSGi environment, including the virtual AbstractFile layer as well as setting the compiler classpath. However we needed to patch Scalate (https://github.com/scalate/scalate/pull/16) to get it working:

    1) The OsgiCompiler override of the ScalaCompiler class was not being enabled properly, and so bundle’s were not being detected as classpath inputs to the compiler, and

    2) The template execution (run-time) classloader was being set to the classloader of the scalate-core bundle, resulting in CNFE’s at runtime.

    The pull request above configures Scalate in an OSGi environment to default to the thread-context classloader at runtime. That seems to be the easiest way to get a reference to the caller’s classloader without the caller having to explicitly inject it (for example, a Spring-DM osgi:service declaration exporting a template service can use the context-class-loader="service-provider" attribute to set this automatically. This also makes the run-time behavior of Scalate OSGi correspond with the existing compile-time behavior which already used the TCCL.

    Therefore a caller to Scalate should set the TCCL to it’s own classloader or explicitly inject the desired classloader to the template engine e.g. templateEngine.classLoader = ... before executing the template.

    Update 31-Aug-2012: Scalate master now contains all of the patches mentioned in this post.

    Update 10-Apr-2013: Scalate 1.6.1, with runtime template compilation via the Scala compiler, is OSGi compatible. Also Scala 2.10 and above are valid OSGi bundles as released.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have my environment setup nicely using Scala, StringTemplate within the Google AppEngine. I
Previously I have only used the Scala templates, but now am I using Java
I'm running a Play! app using Scala templates. However, I can't find an elegant
Using Scala's command line REPL: def foo(x: Int): Unit = {} def foo(x: String):
I'm using Scala's remote actors, but round-trip time (even of a trivial message) is
( Note : I'm using Scala 2.7.7 here, not 2.8). I'm doing something pretty
I am trying to parallelise a code using scala actors. That is my first
I'm working on a project using Scala running Selenium tests as part of a
My company is beginning to write some code using Scala. I've been moved onto
I am generating the scala AST using the following code: val setting = new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.