The documentation says (in section 3.3, sorry for the pdf) -
3.3.2 Implemented JSR-223 interfaces
JSR-223 defines three main interfaces, of which two (Invocable
and Compilable
) are optional.
ABCL implements all the three interfaces - ScriptEngine
and the two optional ones - almost
completely.
Creating an executable jar with ABCL in five easy steps
Step one: Creating a fat jar containing Armed Bear.
I'm going to use maven because it's what I know. Let's create a pom.xml
file.
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.stackoverflow.example</groupId>
<artifactId>ColbertNightmare</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>Stephen Colbert's Nightmare - Armed Bears</name>
<dependencies>
<dependency>
<groupId>org.abcl</groupId>
<artifactId>abcl</artifactId>
<version>1.6.0</version>
</dependency>
</dependencies>
<build>
<finalName>ColbertNightmare</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.stackoverflow.example.Main</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Step two: We need to follow the maven standard directory structure.
We will have one Java class for an entry point. In the folder containing pom.xml
,
mkdir -p src/main/java/com/stackoverflow/example
If you're on Windows, you need to (instead)
mkdir src\main\java\com\stackoverflow\example
Step three: Write the Java code (in the folder we just created)
Create a Main.java
file containing (note I fixed an extra )
bug in your LISP code)
package com.stackoverflow.example;
import javax.script.ScriptException;
import org.armedbear.lisp.scripting.AbclScriptEngine;
import org.armedbear.lisp.scripting.AbclScriptEngineFactory;
public class Main {
public static void main(String[] args) {
AbclScriptEngine scriptEngine = (AbclScriptEngine) new AbclScriptEngineFactory()
.getScriptEngine();
try {
scriptEngine.eval("(format t \"Hello, World!~%\")");
} catch (ScriptException e) {
e.printStackTrace();
}
}
}
Step four: Let's build and package our application.
In the folder containing the pom.xml
,
mvn package
Step five: Run it
$ java -jar target/ColbertNightmare-jar-with-dependencies.jar
Hello, World!
Conclusion
Something like the above can be used to create an executable jar that uses ABCL. Also, Stephen Colbert warned us about bears (before they were armed). I think they're an even bigger threat now.