Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using google java api library in clojure

Tags:

java

clojure

  1. I'm trying to require a java library by Google and call it from Clojure.
  2. I added com.google.api-client/google-api-client to my project.clj according to the groupId, artifactId and version.
  3. lein deps returns no output - seems like it setups all the dependencies successfully.
  4. I have checked the classpath, and it contains the google-api-client.jar (System/getProperty "java.class.path").
  5. user=>(require 'com.google.api-client/google-api-client) returns FileNotFoundException Could not locate google_api_client__init.class or google_api_client.clj on classpath: clojure.lang.RT.load (RT.java:443)

Here is my project.clj:

(defproject textsync "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.5.1"]
                 [com.google.api-client/google-api-client "1.18.0-rc"]

What am I doing wrong?

like image 415
wildeyes Avatar asked Jun 11 '26 10:06

wildeyes


2 Answers

You have to import a java class into the clojure namespace like,

(import 'org.apache.commons.lang.StringUtils) ;replace the java file with what you want

require is only for importing other clojure name spaces. You have to use import when you are importing java classes into clojure name spaces.

like image 100
Abimaran Kugathasan Avatar answered Jun 12 '26 23:06

Abimaran Kugathasan


You most probably simply need to import the classes you want. For instance, you may want to try :

(import '[com.google.api.client.googleapis GoogleUtils]
        '[com.google.api.client.googleapis.services AbstractGoogleClient
                                                    AbstractGoogleClient$Builder])

Note that :

  1. the class is spelled com.google.api.client.googleapis.GoogleUtils (with no dash)

  2. the Clojure syntax for Java nested classes uses $.

like image 42
i-blis Avatar answered Jun 12 '26 23:06

i-blis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!