【发布时间】:2012-03-04 09:16:02
【问题描述】:
我正在开发一个使用 Maven 构建它的 Java 项目。我正在开发的一些功能在 Java 中会很麻烦,但在 Clojure 中很简单,所以我想在 Clojure 中实现它,并让 Java 无缝地使用生成的类。
这是我需要通过的单元测试(src/test/java/com/foo/weather/DataProcessorTest.java):
package com.foo.weather;
import static org.junit.Assert.*;
import org.junit.Test;
import java.util.*;
public class DataProcessorCljTest {
@Test
public void processWithTotalsAndSubTotals() throws Exception {
assertEquals(2, DataProcessor.process(createRawData()).size());
}
private List<List<String>> createRawData() {
List<List<String>> data = new ArrayList<List<String>>();
data.add(new ArrayList<String>(Arrays.asList("2011-11-01", "Temperature", "19.2")));
data.add(new ArrayList<String>(Arrays.asList("2011-11-01", "Pressure", "1.1")));
return data;
}
}
这里是 Clojure 代码 (src/main/clojure/com/foo/weather/data-processor.clj):
(ns com.foo.weather.DataProcessor
(:gen-class
:methods [#^{:static true} [process [java.util.List] java.util.List]]))
(defn process [raw-data]
(java.util.ArrayList. []))
我已将以下内容添加到我的 pom.xml 以构建 Clojure 代码:
<project>
<!-- lots of stuff omitted -->
<build>
<plugins>
<!-- ... -->
<plugin>
<groupId>com.theoryinpractise</groupId>
<artifactId>clojure-maven-plugin</artifactId>
<version>1.3.6</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<!-- ... -->
<repository>
<id>clojure-releases</id>
<url>http://build.clojure.org/releases</url>
</repository>
</repositories>
<dependencies>
<!-- ... -->
<dependency>
<groupId>org.clojure</groupId>
<artifactId>clojure</artifactId>
<version>1.2.1</version>
</dependency>
</dependencies>
</project>
但是,当尝试运行我的单元测试时,编译器会报错“找不到符号变量 DataProcessor”,所以我的 Clojure 代码似乎没有被正确编译。
我注意到的一件事是我的 src/main/clojure 目录在我的 IDE (IntelliJ) 中似乎没有被视为源目录。我在项目视图中右键src/main/clojure,选择“Mark directory as > Source root”,但是在重新导入Maven依赖(即Eclipse中的“Update dependencies”)后,该目录不再被标记为source root .
这让我相信我的问题出在我的 Maven 配置中。
谁能帮忙?
【问题讨论】:
-
使用 Maven 的 Java + Clojure 项目的另一个选择是 Zi