3

I am trying to write a couple of wrapper functions for the code here

it basically has the form (as given in the example page) of

String json = ...
VPackParser parser = new VPackParser.Builder().build();
VPackSlice slice = parser.fromJson(json);

I am aware that To import inner classes one uses $, but every combination of the following doesn't seem to work.

(ns the.pain.is.real
  (:require [clojure.reflect :as r])
  (:import
   com.arangodb.velocypack.VPackBuilder ;; fine
   com.arangodb.velocypack.VPackSlice ;; fine
   com.arangodb.velocypack.VPackParser ;; fine
   com.arangodb.velocypack.VPack ;; fine
   com.arangodb.velocypack.VPackParser$Builder ;; nope
))

I just get a Unhandled java.lang.ClassNotFoundException.

I had worked with some similar code that I had got working using:

(ns winning
  (:import com.arangodb.ArangoDB$Builder))
(.build (-> (new ArangoDB$Builder)
            (.host "127.0.0.1" 8529)
            (.user username)
            (.password password)))

Any ideas?

looking in the jar file does show

com/arangodb/velocypack/VPackParser$Builder.class

Is it just trial and error?

beoliver
  • 5,579
  • 5
  • 36
  • 72
  • If you look inside the jar file you should be able to see the exact names of the class files. Perhaps you won't find a `VPackParser$Builder` there. – Chris Murphy Sep 24 '17 at 13:35
  • @ChrisMurphy - ok. so it looks like there are 20 or so classes named ```com/arangodb/velocypack/VPackBuilder$8.class com/arangodb/velocypack/VPackBuilder$9.class ...``` – beoliver Sep 24 '17 at 13:42
  • @ChrisMurphy - but I was looking at the wrong thing :( - yes there is one `com/arangodb/velocypack/VPackParser$Builder.class` – beoliver Sep 24 '17 at 13:49
  • With Java I would always use a wildcard, so `com.arangodb.velocypack.*`, to make life simpler. Not sure if wildcards are possible for Clojure imports... – Chris Murphy Sep 24 '17 at 13:56
  • Unfortunately a wildcard import is not possible: https://stackoverflow.com/questions/1990714/does-clojure-have-an-equivalent-of-javas-import-package – Chris Murphy Sep 24 '17 at 22:57

1 Answers1

3

Answering my own question.

It appears that two versions were downloaded when using lein deps. Even though only [com.arangodb/velocypack "1.0.0"] was in the project file, both 1.0.0 and 1.0.10 were in the .m2 dir. The class com/arangodb/velocypack/VPackParser$Builder.class is only found in version 1.0.10.

After changing the project file to [com.arangodb/velocypack "1.0.10"] the import works.

beoliver
  • 5,579
  • 5
  • 36
  • 72