How do I create a jar using armed bear common lisp?
Asked Answered
U

1

5

I was wondering if it's possible to create a jar file using armed bear common lisp and if so how to do it.

So in other words, I have this following code (format t "Hello, World!~%")) I can run it in armed bear common lisp. I was wondering how I could create a jar that executes that code.–

Thanks,

Shaun.

Ureter answered 23/4, 2020 at 7:21 Comment(3)
What does your question mean? Please don't repeat the current wording. A jar file is literally a zip file with a special file for some metadata. You can certainly add the abcl classes to any jar. Are you asking how to create a fat jar? Or are you asking how to create a fat jar and invoke a LISP repl on startup? Or are you asking how to create a fat jar and invoke a LISP program on startup? Also, are you expecting us to create an entire bespoke tutorial on all of the above? Also, how is it that my comment is so much longer than your question?Calcimine
So if I have this following code (format t "Hello, World!~%")) I can run it in armed bear common lisp. I was wondering how I could create a jar that executes that code. I hope thta makes sense. Thank youUreter
Might be useful didierverna.net/blog/index.php?post/2011/01/22/…Surveillance
C
9

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.

Calcimine answered 23/4, 2020 at 15:15 Comment(1)
Thanks you so much. Now I just need to work slime out.Ureter

© 2022 - 2024 — McMap. All rights reserved.