简体   繁体   中英

How do I make java libraries visible to clojure?

Ultimately, I want the following to work

(ns grizzler.core
  (:import (com.sun.grizzly.http.embed GrizzlyWebServer)
           (com.sun.grizzly.tcp.http11 GrizzlyAdapter)))

However, I have no idea how to go about this. Do I add stuff to my classpath? Where do I modify my classpath, in my .bashrc or within clojure?

I've found the grizzly project at http://grizzly.java.net/ . But what do I download? How do I install things? I really just have no idea what to do.

Related: Using 3rd party java libraries, like com.jcraft.jsch, with clojure - except that it's not detailed enough for me :(

Edit: I also tried the following in project.clj and it didn't work:

(defproject grizzler "1.0.0-SNAPSHOT"
  :description "FIXME: write description"
  :dependencies [[org.clojure/clojure "1.3.0"]
                 [com.sun.grizzly.http.core "2.1.10"]
                 [com.sun.grizzly.http.embed "2.1.10"]
                 [com.sun.grizzly.tcp.http11 "2.1.10"]])

In addition, I tried net.java.grizzly.http.core , and that didn't work either.

Thanks!

The current consensus on the "right" way to do this is basically "use leiningen". Leiningen is basically a wrapper around maven and uses maven repositories. Most of the time you can find the code you need in a maven repository somewhere, though eventually you will be in this situation where you need to use a jar file. In this case you which lives in your home directory and contains copies of all the jars required to build all your projects. ,该位于主目录中,并包含构建所有项目所需的所有jar的副本。 In cases where the jars you depend on are available from a central repo this local repo acts as a cache so you don't have to download them every time, though you can manually put jars into your local repo if it can't automatically download them.

I recommend watching this video first.

  • check carefully to see if the library you need is already available
  • download the jar you want
  • download leiningen
  • run lein new nameOfYourProject
  • add it to your leiningen project's project.clj
  • run lein deps
    • this will print the full command for installing the jar file to your local maven repo
    • run this command (as printed by leiningen) and your jar file should be copied to the correct location under ~/.m2/...
    • run lein deps again to make sure it finds it
  • add an import statement in your .clj file (as you have above)
  • success!

Debugging this process can be very situation specific, but the denizens of #clojure are usually quite helpful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM