2

I am trying to access the constants from this file in Clojure:

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 attempt:

(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

How do I access these two values?

nha
  • 17,623
  • 13
  • 87
  • 133

1 Answers1

4

The following works with a local java interface:

file: src-java/jroot/Const.java

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

file: project.clj

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

Clojure code:

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

(println Const/ANSWER)

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

Note the space in the :import vector (very important).

Also, if the jar file is local use this syntax:

(defproject test-project "0.1.0-SNAPSHOT"
:description "Blah blah blah"
...
:resource-paths ["resources/Siebel.jar" "resources/SiebelJI_enu.jar"])
Alan Thompson
  • 29,276
  • 6
  • 41
  • 48
  • Thanks, that seems to point to a missing jar indeed. Perhaps a wrong version. I will check that and accept your answer. – nha Jun 02 '17 at 16:49