【问题标题】:Distributing a simple library via clojars通过 clojars 分发一个简单的库
【发布时间】:2017-08-19 08:07:56
【问题描述】:

我已经实现了一个hyphenation algorithm(在命名空间hyphenator-clj.core),在defproject 将其定义为org.clojars.nikonyrh.hyphenator-clj 0.1.0,并将其推送到Clojars。 Uberjar 似乎有 core__init.classcore.cljcore.class 之类的文件。

但是,当我尝试将其用作其他项目的依赖项时,我收到此错误:

$ lein uberjar
Retrieving org/clojars/nikonyrh/hyphenator-clj/org.clojars.nikonyrh.hyphenator-clj/0.1.0/org.clojars.nikonyrh.hyphenator-clj-0.1.0.pom from clojars
Retrieving org/clojars/nikonyrh/hyphenator-clj/org.clojars.nikonyrh.hyphenator-clj/0.1.0/org.clojars.nikonyrh.hyphenator-clj-0.1.0.jar from clojars
Compiling example.core
java.io.FileNotFoundException: Could not locate org/clojars/nikonyrh/hyphenator_clj__init.class or org/clojars/nikonyrh/hyphenator_clj.clj on classpath. Please check that namespaces with dashes use underscores in the Clojure file name., compiling:(core.clj:1:1)
Exception in thread "main" java.io.FileNotFoundException: Could not locate org/clojars/nikonyrh/hyphenator_clj__init.class or org/clojars/nikonyrh/hyphenator_clj.clj on classpath. Please check that namespaces with dashes use underscores in the Clojure file name., compiling:(core.clj:1:1)
    at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3657)
    at clojure.lang.Compiler.compile1(Compiler.java:7474)
    at clojure.lang.Compiler.compile1(Compiler.java:7464)
    at clojure.lang.Compiler.compile(Compiler.java:7541)
    at clojure.lang.RT.compile(RT.java:406)
    at clojure.lang.RT.load(RT.java:451)
    at clojure.lang.RT.load(RT.java:419)
    at clojure.core$load$fn__5677.invoke(core.clj:5893)
    ...

我必须更改项目的文件夹结构以使其与预期的org/clojars/nikonyrh/hyphenator_clj__init.class 匹配,还是我可以以某种方式覆盖当前行为?如果有关于这方面的好教程,我很乐意阅读。

基本上我想让这个示例项目工作。项目.clj:

(defproject example "0.0.1-SNAPSHOT"
  :description ""
  :dependencies [[org.clojure/clojure "1.8.0"]
                 [org.clojars.nikonyrh.hyphenator-clj "0.1.0"]]
  :javac-options ["-target" "1.6" "-source" "1.6" "-Xlint:-options"]
  :aot [example.core]
  :main example.core)

src/example/core.clj:

(ns example.core
  (:require [org.clojars.nikonyrh.hyphenator-clj :as h])
  (:gen-class))

(defn -main [& argv] (doseq [arg argv] (println (h/hyphenate arg :hyphen \-))))

我怀疑我的english.txt 也在错误的目录中,因为它不包含在uberjar 中,但资源文件是另一个主题。

【问题讨论】:

    标签: clojure leiningen clojars


    【解决方案1】:

    您最好不要在命名空间hyphenator-clj 中使用连字符。为什么不直接使用hyphenator?但是如果你这样做,我怀疑目录的名称应该有一个下划线而不是一个连字符,所以是:hyphenator_clj

    如果解决该问题没有帮助,那么需要注意的另一件事是,我无法从您的问题中看到,core.clj 在目录结构中的确切位置,project.clj 是否反映了这一点?例如,命名空间hyphenator-clj.core 的路径是否位于项目根目录下的src 目录中?项目的根被定义为project.clj 所在的位置。

    在这个问题中可以看到的其他一点是,您是否可以让程序仅在本地运行,而无需将其打包到 uberjar 中并将其运送到 clojars。我的猜测是它确实可以在本地工作,但说明这一点会有所帮助。

    好的,现在看看你的链接。您可能想阅读一个部署到 clojars 的工作项目,它的名称中有连字符,例如 here。您可能注意到的第一个区别是您使用的项目名称相当长:org.clojars.nikonyrh.hyphenator-clj。它应该只是hyphenator-clj。我还建议像该项目一样使用以“-SNAPSHOT”结尾的标识符。

    但纵观全局,您在 cmets 中提出的一个好主意是在完全不使用 Clojars 的情况下进行测试。为此,请在要从另一个 lein 项目中使用的库上使用 lein install

    【讨论】:

    • 该文件位于 src/hyphenator_clj/core.clj (问题中的第一个链接是 Github)。该项目是 hyphenator-clj,因为它是我早期项目 hyphenator-php 的一个端口。当然,在 Clojar 的上下文中,“clj”只是额外的噪音。
    • hyphenator-clj 在某种意义上“在本地”工作,您可以构建它并执行 jar,但除了通过 Clojars 之外,我还没有尝试在其他项目上使用它。
    【解决方案2】:

    啊哈至少我现在对这个过程了解得更好了,基本上我的require必须匹配使用的JAR文件的结构,这可能与项目名称有很大不同。例如cc.qbits/spandex 实际上是required 作为qbits.spandex

    english.txt 依赖项已通过将其移动到 resources 文件夹、将新版本部署到 Clojars 并导入 JAR 中存在的依赖项来修复:

    (ns example.core
      (:require [hyphenator-clj.core :as h])
      (:gen-class))
    
    (defn -main [& argv] (doseq [arg argv] (println (h/hyphenate arg :hyphen \-))))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-04
      • 2014-06-30
      • 2020-01-10
      • 1970-01-01
      • 2014-12-06
      • 2013-02-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多