Clojure 访问 Java 接口常量

Clojure access Java Interface constants

我正在尝试从 Clojure 中的 this file 访问常量:

public interface CacheConstants
{
    /** This is the name of the config file that we will look for by default. */
    String DEFAULT_CONFIG = "/cache.ccf";

    /** Delimiter of a cache name component. This is used for hierarchical deletion */
    String NAME_COMPONENT_DELIMITER = ":";
 }

Clojure 尝试:

(import '[org.apache.jcs.engine.CacheConstants])
org.apache.jcs.engine.CacheConstants/DEFAULT_CONFIG

;; clojure.lang.Compiler$CompilerException: java.lang.ClassNotFoundException: org.apache.jcs.engine.CacheConstants

如何访问这两个值?

以下使用本地 java 接口:

文件:src-java/jroot/Const.java

package jroot;
public interface Const {
  long ANSWER = 42;

文件:project.clj

(defproject clj "0.1.0-SNAPSHOT"
  <snip>
  :java-source-paths ["src-java"]
)

Clojure 代码:

(ns tst.clj.core
  (:require  ...)
  (:import [jroot Const])
)

(println Const/ANSWER)

---------
Const/ANSWER => 42

注意:import向量中的space(非常重要)。

此外,如果 the jar file is local 使用此语法:

(defproject test-project "0.1.0-SNAPSHOT"
:description "Blah blah blah"
...
:resource-paths ["resources/Siebel.jar" "resources/SiebelJI_enu.jar"])