documentation 说(在第 3.3 节中,对 pdf 感到抱歉)-
3.3.2 实现的 JSR-223 接口
JSR-223 定义了三个主要接口,其中两个(Invocable 和Compilable)是可选的。
ABCL 实现了所有三个接口 - ScriptEngine 和两个可选接口 - 几乎
完全地。
通过五个简单的步骤使用 ABCL 创建可执行 jar
第一步:创建一个包含武装熊的胖罐子。
我将使用 maven,因为这是我所知道的。让我们创建一个pom.xml 文件。
<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>
第二步:我们需要遵循maven标准的目录结构。
我们将有一个 Java 类作为入口点。在包含pom.xml的文件夹中,
mkdir -p src/main/java/com/stackoverflow/example
如果您使用的是 Windows,则需要(而不是)
mkdir src\main\java\com\stackoverflow\example
第三步:编写Java代码(在我们刚刚创建的文件夹中)
创建一个 Main.java 文件,其中包含(注意我在 LISP 代码中修复了一个额外的 ) 错误)
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();
}
}
}
第四步:让我们构建和打包我们的应用程序。
在包含pom.xml的文件夹中,
mvn package
第五步:运行
$ java -jar target/ColbertNightmare-jar-with-dependencies.jar
Hello, World!
结论
类似上面的东西可以用来创建一个使用 ABCL 的可执行 jar。此外,Stephen Colbert 警告我们关于熊(在他们武装之前)。我认为他们现在是一个更大的威胁。