Using the jsr223 engine in maven

I took notice that the Lucee 5 build process itself uses the JSR 223 scripting engine to generate lar files.

I am interested in using the same thing to package my cfm resources into .lar files for final distribution. So far I’ve been having problems getting it to actually run.

Here’s what I have so far:

pom.xml

<plugin>
  <artifactId>maven-antrun-plugin</artifactId>
  <version>1.8</version>
  <executions>
    <execution>
      <phase>compile</phase>
      <goals><goal>run</goal></goals>
      
      <configuration>
        <target>
          <property name="plugin_classpath" refid="maven.plugin.classpath" />
          <property name="runtime_classpath" refid="maven.runtime.classpath"/>
          
          <java classname="org.apache.tools.ant.launch.Launcher" dir="." fork="true" failonerror="false">
            <classpath path="${java.class.path}">
              <pathelement path="${plugin_classpath}" />
                  <pathelement path="${runtime_classpath}"/>
            </classpath>
            
            <arg value="-f" />
            <arg value="src/build/compile-lars.xml" />
            
            <jvmarg value="-Dlucee.base.dir=build/tmp/"/>
          </java>
        </target>
        
      </configuration>
    </execution>
  </executions>
  <dependencies>
    <dependency>
      <groupId>org.apache.ant</groupId>
      <artifactId>ant</artifactId>
      <version>1.9.5</version>
    </dependency>
  </dependencies>
</plugin>

src/build/compile-lars.xml

<project default="run">
  <target name="run">
    <script language="CFML">
      echo("cfml script in a build!!! woohoo!!!");
    </script>
  </target>
</project>

build output:

main:
     [java] Buildfile: C:\Users\jesse.shaffer\git\app\src\build\compile-lars.xml
     [java]
     [java] run:
     [java]    [script] root-directory:build\tmp
     [java]    [script] classic-root-directory:C:\Users\jesse.shaffer\.m2\repository\org\lucee\lucee\5.0.0.98-SNAPSHOT
     [java]    [script] ScriptEngineManager providers.next(): javax.script.ScriptEngineFactory: Provider lucee.runtime.script.LuceeScriptEngineFactory could not
 be instantiated
     [java]    [script] org.osgi.framework.BundleException: Error creating bundle cache.
     [java]    [script]         at org.apache.felix.framework.Felix.init(Felix.java:645)
     [java]    [script]         at org.apache.felix.framework.Felix.start(Felix.java:893)
     [java]    [script]         at lucee.loader.engine.CFMLEngineFactory.getFelix(CFMLEngineFactory.java:432)
     [java]    [script]         at lucee.loader.osgi.BundleLoader.loadBundles(BundleLoader.java:169)
     [java]    [script]         at lucee.loader.engine.CFMLEngineFactory.getCore(CFMLEngineFactory.java:465)
     [java]    [script]         at lucee.loader.engine.CFMLEngineFactory.initEngine(CFMLEngineFactory.java:296)
     [java]    [script]         at lucee.loader.engine.CFMLEngineFactory.initEngineIfNecessary(CFMLEngineFactory.java:253)
     [java]    [script]         at lucee.loader.engine.CFMLEngineFactory.getInstance(CFMLEngineFactory.java:149)
     [java]    [script]         at lucee.runtime.script.BaseScriptEngineFactory.<init>(BaseScriptEngineFactory.java:61)
     [java]    [script]         at lucee.runtime.script.CFMLScriptEngineFactory.<init>(CFMLScriptEngineFactory.java:27)
     [java]    [script]         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
     [java]    [script]         at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
     [java]    [script]         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
     [java]    [script]         at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
     [java]    [script]         at java.lang.Class.newInstance(Class.java:438)
     [java]    [script]         at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:380)
     [java]    [script]         at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
     [java]    [script]         at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
     [java]    [script]         at javax.script.ScriptEngineManager.initEngines(ScriptEngineManager.java:122)
     [java]    [script]         at javax.script.ScriptEngineManager.init(ScriptEngineManager.java:84)
     [java]    [script]         at javax.script.ScriptEngineManager.<init>(ScriptEngineManager.java:61)
     [java]    [script]         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
     [java]    [script]         at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
     [java]    [script]         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
     [java]    [script]         at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
     [java]    [script]         at org.apache.tools.ant.util.ReflectWrapper.<init>(ReflectWrapper.java:42)
     [java]    [script]         at org.apache.tools.ant.util.optional.JavaxScriptRunner.createEngine(JavaxScriptRunner.java:133)
     [java]    [script]         at org.apache.tools.ant.util.optional.JavaxScriptRunner.evaluateScript(JavaxScriptRunner.java:82)
     [java]    [script]         at org.apache.tools.ant.util.optional.JavaxScriptRunner.executeScript(JavaxScriptRunner.java:67)
     [java]    [script]         at org.apache.tools.ant.taskdefs.optional.Script.execute(Script.java:53)
     [java]    [script]         at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
     [java]    [script]         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     [java]    [script]         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
     [java]    [script]         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     [java]    [script]         at java.lang.reflect.Method.invoke(Method.java:483)
     [java]    [script]         at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
     [java]    [script]         at org.apache.tools.ant.Task.perform(Task.java:348)
     [java]    [script]         at org.apache.tools.ant.Target.execute(Target.java:435)
     [java]    [script]         at org.apache.tools.ant.Target.performTasks(Target.java:456)
     [java]    [script]         at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
     [java]    [script]         at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
     [java]    [script]         at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
     [java]    [script]         at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
     [java]    [script]         at org.apache.tools.ant.Main.runBuild(Main.java:853)
     [java]    [script]         at org.apache.tools.ant.Main.startAnt(Main.java:235)
     [java]    [script]         at org.apache.tools.ant.launch.Launcher.run(Launcher.java:285)
     [java]    [script]         at org.apache.tools.ant.launch.Launcher.main(Launcher.java:112)
     [java]    [script] Caused by: java.lang.Exception: Unable to lock bundle cache: java.nio.channels.OverlappingFileLockException
     [java]    [script]         at org.apache.felix.framework.cache.BundleCache.<init>(BundleCache.java:176)
     [java]    [script]         at org.apache.felix.framework.Felix.init(Felix.java:640)
     [java]    [script]         ... 46 more
     [java]    [script] javax.servlet.ServletException: org.osgi.framework.BundleException: Error creating bundle cache.
     [java]    [script]         at lucee.loader.engine.CFMLEngineFactory.initEngine(CFMLEngineFactory.java:331)
     [java]    [script]         at lucee.loader.engine.CFMLEngineFactory.initEngineIfNecessary(CFMLEngineFactory.java:253)
     [java]    [script]         at lucee.loader.engine.CFMLEngineFactory.getInstance(CFMLEngineFactory.java:149)
     [java]    [script]         at lucee.runtime.script.BaseScriptEngineFactory.<init>(BaseScriptEngineFactory.java:61)
     [java]    [script]         at lucee.runtime.script.CFMLScriptEngineFactory.<init>(CFMLScriptEngineFactory.java:27)
     [java]    [script]         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
     [java]    [script]         at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
     [java]    [script]         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
     [java]    [script]         at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
     [java]    [script]         at java.lang.Class.newInstance(Class.java:438)
     [java]    [script]         at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:380)
     [java]    [script]         at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
     [java]    [script]         at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
     [java]    [script]         at javax.script.ScriptEngineManager.initEngines(ScriptEngineManager.java:122)
     [java]    [script]         at javax.script.ScriptEngineManager.init(ScriptEngineManager.java:84)
     [java]    [script]         at javax.script.ScriptEngineManager.<init>(ScriptEngineManager.java:61)
     [java]    [script]         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
     [java]    [script]         at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
     [java]    [script]         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
     [java]    [script]         at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
     [java]    [script]         at org.apache.tools.ant.util.ReflectWrapper.<init>(ReflectWrapper.java:42)
     [java]    [script]         at org.apache.tools.ant.util.optional.JavaxScriptRunner.createEngine(JavaxScriptRunner.java:133)
     [java]    [script]         at org.apache.tools.ant.util.optional.JavaxScriptRunner.evaluateScript(JavaxScriptRunner.java:82)
     [java]    [script]         at org.apache.tools.ant.util.optional.JavaxScriptRunner.executeScript(JavaxScriptRunner.java:67)
     [java]    [script]         at org.apache.tools.ant.taskdefs.optional.Script.execute(Script.java:53)
     [java]    [script]         at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
     [java]    [script]         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     [java]    [script]         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
     [java]    [script]         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     [java]    [script]         at java.lang.reflect.Method.invoke(Method.java:483)
     [java]    [script]         at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
     [java]    [script]         at org.apache.tools.ant.Task.perform(Task.java:348)
     [java]    [script]         at org.apache.tools.ant.Target.execute(Target.java:435)
     [java]    [script]         at org.apache.tools.ant.Target.performTasks(Target.java:456)
     [java]    [script]         at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
     [java]    [script]         at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
     [java]    [script]         at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
     [java]    [script]         at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
     [java]    [script]         at org.apache.tools.ant.Main.runBuild(Main.java:853)
     [java]    [script]         at org.apache.tools.ant.Main.startAnt(Main.java:235)
     [java]    [script]         at org.apache.tools.ant.launch.Launcher.run(Launcher.java:285)
     [java]
     [java] BUILD FAILED   [script]     at org.apache.tools.ant.launch.Launcher.main(Launcher.java:112)
     [java]
     [java]    [script] Caused by: org.osgi.framework.BundleException: Error creating bundle cache.
     [java]    [script]         at org.apache.felix.framework.Felix.init(Felix.java:645)C:\Users\jesse.shaffer\git\app\src\build\compile-lars.xml:3
: Unable to create javax script engine for CFML
     [java]
     [java]
     [java] Total time: 2 seconds
     [java]    [script]         at org.apache.felix.framework.Felix.start(Felix.java:893)
     [java]    [script]         at lucee.loader.engine.CFMLEngineFactory.getFelix(CFMLEngineFactory.java:432)
     [java]    [script]         at lucee.loader.osgi.BundleLoader.loadBundles(BundleLoader.java:169)
     [java]    [script]         at lucee.loader.engine.CFMLEngineFactory.getCore(CFMLEngineFactory.java:465)
     [java]    [script]         at lucee.loader.engine.CFMLEngineFactory.initEngine(CFMLEngineFactory.java:296)
     [java]    [script]         ... 41 more
     [java]    [script] Caused by: java.lang.Exception: Unable to lock bundle cache: java.nio.channels.OverlappingFileLockException
     [java]    [script]         at org.apache.felix.framework.cache.BundleCache.<init>(BundleCache.java:176)
     [java]    [script]         at org.apache.felix.framework.Felix.init(Felix.java:640)
     [java]    [script]         ... 46 more
     [java]    [script] ScriptEngineManager providers.next(): javax.script.ScriptEngineFactory: Provider lucee.runtime.script.CFMLScriptEngineFactory could not
be instantiated
     [java] Java Result: 1

Any idea what may be causing this?

you can download a much more simple example here:
http://dev.lucee.org/download/ant.zip

this zip does not include the OSGi bundles needed by lucee, so Lucee will start to download them on the first startup, unless you copy them to this location /assets/lucee/lucee-server/bundles, you can download them here (http://preview.lucee.org/download/ -> “Dependencies”)

@micstriit, thanks for the advice - I just found this worked before I read your comment:

<plugin>
  <artifactId>maven-antrun-plugin</artifactId>
  <version>1.8</version>
  <executions>
    <execution>
      <phase>compile</phase>
      <goals><goal>run</goal></goals>
      
      <configuration>
        <target>
          <property name="plugin_classpath" refid="maven.plugin.classpath" />
          <property name="runtime_classpath" refid="maven.runtime.classpath"/>
          
          <!-- copy the lucee dependencies to the bundles dir -->
          <copy todir="build/tmp/lucee-server/bundles" flatten="true">
            <path>
              <pathelement path="${plugin_classpath}"/>
            </path>
          </copy>
          
          <java classname="org.apache.tools.ant.launch.Launcher" dir="." fork="true" failonerror="false">
            <classpath path="${java.class.path}">
              <pathelement path="${plugin_classpath}" />
              <pathelement path="${runtime_classpath}"/>
            </classpath>
            
            <arg value="-f" />
            <arg value="src/build/compile-lars.xml" />
            
            <jvmarg value="-Dlucee.base.dir=build/tmp/"/>
          </java>
        </target>
        
      </configuration>
    </execution>
  </executions>
  <dependencies>
    <dependency>
      <groupId>org.apache.ant</groupId>
      <artifactId>ant</artifactId>
      <version>1.9.5</version>
    </dependency>

    <!-- add lucee as a dependency to this execution also -->
    <dependency>
      <groupId>org.lucee</groupId>
      <artifactId>lucee</artifactId>
      <version>${lucee.version}</version>
    </dependency>
  </dependencies>
</plugin>

@dajester2013 I think a blog post or something about what you get working would be pretty cool. There’s a lot of possibilities here.

maybe it should also include how to install Lucee in ant (classpath), so must of the addional steps are not necessary at all.

@bdw429s I guess I ought to start a blog then… lol. I’ll share when it’s up. By way of preview, I’ve successfully set up a project to build Lucee5 component archive libraries (the final artifact is a .lar file to be deployed as a component mapping).

(I accidentally posted this on the wrong thread, moved it here…)

So I started writing some posts on a brand new blog, and realized just how terrible I am at writing blog posts. So I put a repo on github with some (very) basic example projects to show how I’m approaching working with Maven for Lucee projects:

I plan on working on some more examples and adding them. Also, I am pretty much still a newcomer to Maven, so if anyone sees an area that I implemented poorly, please let me know.

1 Like