Maven中的混合Clojure和Java项目

时间:2017-09-27 07:13:02

标签: java maven clojure clojure-maven-plugin

我有maven项目,在目录src/main/clojure中我放了代码:https://github.com/8protons/url62/blob/master/src/url62/core.clj

我想在generate-id的Java代码中执行函数src/main/java

IFn require = Clojure.var("clojure.core", "require");
require.invoke(Clojure.read("url62.core"));

IFn plus = Clojure.var("url62.core", "generate-id");
Object result = plus.invoke(UUID.randomUUID().toString());
System.out.println(result);

Maven配置:

<package>jar</package>

<dependencies>
    <dependency>
        <groupId>org.clojure</groupId>
        <artifactId>clojure</artifactId>
        <version>1.8.0</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>com.theoryinpractise</groupId>
            <artifactId>clojure-maven-plugin</artifactId>
            <version>1.8.1</version>
            <extensions>true</extensions>
            <executions>
                <execution>
                    <id>compile</id>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

编译好

target/classes/
├── core.clj
└── url62
    ├── core.clj
    ├── core$fn__3.class
    ├── core$generate_id.class
    ├── core__init.class
    ├── core$int_to_base62.class
    └── core$loading__5569__auto____1.class

但Java代码失败:

clojure.lang.ArityException: Wrong number of args (1) passed to: core/generate-id

at clojure.lang.AFn.throwArity(AFn.java:429)
at clojure.lang.AFn.invoke(AFn.java:36)
at clojure.lang.Var.invoke(Var.java:383)
at url62.Url62Test.name(Url62Test.java:17)

1 个答案:

答案 0 :(得分:2)

好的,clojoure函数没有参数:(

Object result = plus.invoke();