当使用gen-class
这个编译罚款:
(ns clj.sandbox)
(defn -hello
[this]
"Hello World")
(gen-class
:name com.sandbox.GeneratedClass
:methods [[hello [] String]])
但如果你这样做:
(ns clj.sandbox)
(def my-methods (atom [[hello [] String]]))
(defn -hello
[this]
"Hello World")
(gen-class
:name com.sandbox.GeneratedClass
:methods @my-methods)
你得到这个错误:
CompilerException java.lang.RuntimeException: Unable to resolve symbol: hello in this context, 编译:(clj\sandbox.clj:3:17)
有没有办法解决这个错误?我希望能够传入:methods
值而不是内联定义它。
如果它很重要,这是我用来生成它的 pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<artifactId>sandbox</artifactId>
<groupId>com.sandbox</groupId>
<version>1.0-SNAPSHOT</version>
<packaging>clojure</packaging>
<modelVersion>4.0.0</modelVersion>
<build>
<plugins>
<plugin>
<groupId>com.theoryinpractise</groupId>
<artifactId>clojure-maven-plugin</artifactId>
<version>1.3.13</version>
<extensions>true</extensions>
<configuration>
<sourceDirectories>
<sourceDirectory>src</sourceDirectory>
</sourceDirectories>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.clojure</groupId>
<artifactId>clojure</artifactId>
<version>1.5.1</version>
</dependency>
</dependencies>
</project>