Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>My team now has Scala compilation and execution working for Scalate within OSGi.</p> <p>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 <a href="https://github.com/guggla/guggla" rel="nofollow">Guggla</a> 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 <a href="https://github.com/scalate/scalate" rel="nofollow">Scalate</a> project (see <a href="https://github.com/vivosys/scalate/blob/master/scalate-core/src/main/scala/org/fusesource/scalate/support/ScalaCompiler.scala" rel="nofollow">ScalaCompiler</a> but note our changes to it below).</p> <p>We chose the OSGi-ified scala bundles (<a href="http://repo1.maven.org/maven2/org/apache/servicemix/bundles/org.apache.servicemix.bundles.scala-compiler/" rel="nofollow">compiler</a> and <a href="http://repo1.maven.org/maven2/org/apache/servicemix/bundles/org.apache.servicemix.bundles.scala-library/" rel="nofollow">library</a>) from the ServiceMix project. See <a href="https://issues.apache.org/jira/browse/SMX4-1048" rel="nofollow">issue SMX-1048 (with patch)</a> on the scala-compiler bundle.</p> <p>Our original intent was to get this working in Scalate, and so the rest of this answer is specific to that project.</p> <p>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 (<a href="https://github.com/scalate/scalate/pull/16" rel="nofollow">https://github.com/scalate/scalate/pull/16</a>) to get it working:</p> <p>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</p> <p>2) The template execution (run-time) classloader was being set to the classloader of the scalate-core bundle, resulting in CNFE's at runtime.</p> <p>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 <code>osgi:service</code> declaration exporting a template service can use the <code>context-class-loader="service-provider"</code> 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.</p> <p>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. <code>templateEngine.classLoader = ...</code> before executing the template.</p> <p>Update 31-Aug-2012: Scalate master now contains all of the patches mentioned in this post.</p> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload