Running non-web-bound engine in JBoss 7
Currently, in JBoss 7.1, the standard TemplateEngine cannot initialize the Scala compiler. Same code with same dependencies as a standalone application works. Infrastructure based on ServletTemplateEngine run from a web application under JBoss works too. Apparently, the problem is caused by an intricate JBoss module classloader which ClassPathBuilder cannot crack to extract actual classpaths to pass to the Scala compiler. I would use the servlet-oriented class, however for some cases, I need to process templates outside of threads processing web request, for instance to generate HTML e-mails initiated by a scheduler, and then I get:
org.fusesource.scalate.TemplateException: object scala not found.
org.fusesource.scalate.TemplateEngine.compileAndLoad(TemplateEngine.scala:834)
org.fusesource.scalate.TemplateEngine.compileAndLoadEntry(TemplateEngine.scala:691)
org.fusesource.scalate.TemplateEngine.liftedTree1$1(TemplateEngine.scala:411)
org.fusesource.scalate.TemplateEngine.load(TemplateEngine.scala:405)
org.fusesource.scalate.TemplateEngine.layout(TemplateEngine.scala:604)
PS. I use SCAML.
org.fusesource.scalate.TemplateException: object scala not found.
org.fusesource.scalate.TemplateEngine.compileAndLoad(TemplateEngine.scala:834)
org.fusesource.scalate.TemplateEngine.compileAndLoadEntry(TemplateEngine.scala:691)
org.fusesource.scalate.TemplateEngine.liftedTree1$1(TemplateEngine.scala:411)
org.fusesource.scalate.TemplateEngine.load(TemplateEngine.scala:405)
org.fusesource.scalate.TemplateEngine.layout(TemplateEngine.scala:604)
PS. I use SCAML.
Leave a comment
on 2012-12-13 22:28 *
By stefan.gheorghiu
Description changed from Currently, in JBoss 7.1, th... to Currently, in JBoss 7.1, th...
Priority changed from Normal (3) to High (2)
on 2012-12-22 19:48 *
By maslovalex
In JBoss 5.1.2 EAP I am using
in the Boot class. I don't know if it works in JBoss 7.
imports from jboss
and dependencies needed to compile it (long list, but mostly because of exclusions). Most probably jboss 7 uses different versions
def module4class(cl: ClassLoader): Module = if (null == cl) null else ClassLoading.getModuleForClassLoader(cl) match {
case null => module4class(cl.getParent)
case m => m
}
module4class(classOf[scala.ScalaObject].getClassLoader) match {
case null => error("Module for [ScalaObject] is null")
case module =>
info("Module for [ScalaObject] is " + module)
import scala.collection.JavaConversions._
val cpList = module.getResources("").map {
u =>
val vf = VFS.getRoot(u)
val str = VFSUtils.stripProtocol(VFSUtils.getRealURL(vf).toURI)
str.substring(0, str.length - 1)
}
engine.classpath = cpList.foldLeft(new StringBuilder(engine.classpath))((sb, cp) => sb.append(File.pathSeparatorChar).append(cp)).toString
info("SCP: " + engine.classpath)
}
in the Boot class. I don't know if it works in JBoss 7.
imports from jboss
import org.jboss.classloading.spi.dependency.ClassLoading
import org.jboss.classloading.spi.dependency.Module
import org.jboss.virtual.VFS
import org.jboss.virtual.VFSUtils
and dependencies needed to compile it (long list, but mostly because of exclusions). Most probably jboss 7 uses different versions
<dependency>
<groupId>org.jboss.cl</groupId>
<artifactId>jboss-classloading</artifactId>
<version>2.0.9.GA</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.man</groupId>
<artifactId>jboss-metatype</artifactId>
<version>2.1.1.SP1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.man</groupId>
<artifactId>jboss-managed</artifactId>
<version>2.1.1.SP1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-vfs</artifactId>
<version>2.2.0.SP1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.jbossas</groupId>
<artifactId>jboss-as-tomcat</artifactId>
<version>5.1.0.GA</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>jboss-as-connector</artifactId>
<groupId>org.jboss.jbossas</groupId>
</exclusion>
<exclusion>
<artifactId>jboss-deployers-spi</artifactId>
<groupId>org.jboss.deployers</groupId>
</exclusion>
<exclusion>
<artifactId>jboss-deployers-vfs</artifactId>
<groupId>org.jboss.deployers</groupId>
</exclusion>
<exclusion>
<artifactId>jboss-jacc-api</artifactId>
<groupId>org.jboss.javaee</groupId>
</exclusion>
<exclusion>
<artifactId>jboss-deployers-vfs-spi</artifactId>
<groupId>org.jboss.deployers</groupId>
</exclusion>
<exclusion>
<artifactId>jboss-as-ejb3</artifactId>
<groupId>org.jboss.jbossas</groupId>
</exclusion>
<exclusion>
<artifactId>jbossws-spi</artifactId>
<groupId>org.jboss.ws</groupId>
</exclusion>
<exclusion>
<artifactId>jboss-as-security</artifactId>
<groupId>org.jboss.jbossas</groupId>
</exclusion>
<exclusion>
<artifactId>jboss-ha-server-cache-jbc</artifactId>
<groupId>org.jboss.cluster</groupId>
</exclusion>
<exclusion>
<artifactId>jboss-metadata</artifactId>
<groupId>org.jboss.metadata</groupId>
</exclusion>
<exclusion>
<artifactId>jboss-aop</artifactId>
<groupId>org.jboss.aop</groupId>
</exclusion>
<exclusion>
<artifactId>jboss-deployers-structure-spi</artifactId>
<groupId>org.jboss.deployers</groupId>
</exclusion>
<exclusion>
<artifactId>jboss-as-iiop</artifactId>
<groupId>org.jboss.jbossas</groupId>
</exclusion>
<exclusion>
<artifactId>jboss-ejb-api</artifactId>
<groupId>org.jboss.javaee</groupId>
</exclusion>
<exclusion>
<artifactId>jboss-ha-server-cache-spi</artifactId>
<groupId>org.jboss.cluster</groupId>
</exclusion>
<exclusion>
<artifactId>jboss-deployers-core-spi</artifactId>
<groupId>org.jboss.deployers</groupId>
</exclusion>
<exclusion>
<artifactId>jbossxb</artifactId>
<groupId>org.jboss</groupId>
</exclusion>
<exclusion>
<artifactId>jboss-as-j2se</artifactId>
<groupId>org.jboss.jbossas</groupId>
</exclusion>
<exclusion>
<artifactId>jbossws-native-jaxws</artifactId>
<groupId>org.jboss.ws.native</groupId>
</exclusion>
<exclusion>
<artifactId>jboss-jca-api</artifactId>
<groupId>org.jboss.javaee</groupId>
</exclusion>
<exclusion>
<artifactId>jboss-ejb3-core</artifactId>
<groupId>org.jboss.ejb3</groupId>
</exclusion>
<exclusion>
<artifactId>jboss-as-server</artifactId>
<groupId>org.jboss.jbossas</groupId>
</exclusion>
<exclusion>
<artifactId>jboss-ha-server-api</artifactId>
<groupId>org.jboss.cluster</groupId>
</exclusion>
<exclusion>
<artifactId>jboss-as-system-jmx</artifactId>
<groupId>org.jboss.jbossas</groupId>
</exclusion>
<exclusion>
<artifactId>jboss-deployers-impl</artifactId>
<groupId>org.jboss.deployers</groupId>
</exclusion>
<exclusion>
<artifactId>concurrent</artifactId>
<groupId>oswego-concurrent</groupId>
</exclusion>
<exclusion>
<artifactId>jbosssx-client</artifactId>
<groupId>org.jboss.security</groupId>
</exclusion>
<exclusion>
<artifactId>log4j</artifactId>
<groupId>log4j</groupId>
</exclusion>
<exclusion>
<artifactId>jboss-classloader</artifactId>
<groupId>org.jboss.cl</groupId>
</exclusion>
<exclusion>
<artifactId>jgroups</artifactId>
<groupId>jgroups</groupId>
</exclusion>
<exclusion>
<artifactId>jbossweb</artifactId>
<groupId>jboss.web</groupId>
</exclusion>
<exclusion>
<artifactId>jboss-common-core</artifactId>
<groupId>org.jboss</groupId>
</exclusion>
<exclusion>
<artifactId>jsf-impl</artifactId>
<groupId>javax.faces</groupId>
</exclusion>
<exclusion>
<artifactId>xml-apis</artifactId>
<groupId>apache-xerces</groupId>
</exclusion>
<exclusion>
<artifactId>jboss-serialization</artifactId>
<groupId>jboss</groupId>
</exclusion>
<exclusion>
<artifactId>jboss-jaspi-api</artifactId>
<groupId>org.jboss.javaee</groupId>
</exclusion>
<exclusion>
<artifactId>jsf-api</artifactId>
<groupId>javax.faces</groupId>
</exclusion>
<exclusion>
<artifactId>jaas</artifactId>
<groupId>javax.security</groupId>
</exclusion>
<exclusion>
<artifactId>ejb3-persistence</artifactId>
<groupId>org.hibernate</groupId>
</exclusion>
<exclusion>
<artifactId>jacorb</artifactId>
<groupId>jacorb</groupId>
</exclusion>
<exclusion>
<artifactId>jboss-logging-spi</artifactId>
<groupId>org.jboss.logging</groupId>
</exclusion>
<exclusion>
<artifactId>jta</artifactId>
<groupId>javax.transaction</groupId>
</exclusion>
<exclusion>
<artifactId>jboss-deployment-spi</artifactId>
<groupId>org.jboss.integration</groupId>
</exclusion>
<exclusion>
<artifactId>jboss-vfs</artifactId>
<groupId>org.jboss</groupId>
</exclusion>
<exclusion>
<artifactId>jboss-security-spi</artifactId>
<groupId>org.jboss.security</groupId>
</exclusion>
</exclusions>
</dependency>
on 2013-03-21 07:13 *
By stefan.gheorghiu
Alexander,
Thank you for the suggestion. Unfortunately, class loading was fully reworked in JBoss 7. My problem became even more complicated when I had to migrate the deployment structure to a skinny WAR inside EAR, i.e. all my libraries moved from *.war:/WEB-INF/lib to *.ear:/lib. However, I've managed to collect physical paths to all dependent JAR files with a quick and dirty approach employing reflection to org.jboss.modules.ModuleClassLoader.
I suppose, there will never be a proper solution to this problem since application containers aim to isolate low-level class loading details from applications and, on the other hand, the Scala compiler cannot use runtime class loading because it needs to access the raw binary data of class files to extract Scala-specific extensions which otherwise are not provided by the standard class loader interface.
Thank you for the suggestion. Unfortunately, class loading was fully reworked in JBoss 7. My problem became even more complicated when I had to migrate the deployment structure to a skinny WAR inside EAR, i.e. all my libraries moved from *.war:/WEB-INF/lib to *.ear:/lib. However, I've managed to collect physical paths to all dependent JAR files with a quick and dirty approach employing reflection to org.jboss.modules.ModuleClassLoader.
I suppose, there will never be a proper solution to this problem since application containers aim to isolate low-level class loading details from applications and, on the other hand, the Scala compiler cannot use runtime class loading because it needs to access the raw binary data of class files to extract Scala-specific extensions which otherwise are not provided by the standard class loader interface.