Java leiningen - 如何为本地 jar 添加依赖项?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2404426/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
leiningen - how to add dependencies for local jars?
提问by signalseeker
I want to use leiningen to build and develop my clojure project. Is there a way to modify project.clj to tell it to pick some jars from local directories?
我想使用 leiningen 来构建和开发我的 clojure 项目。有没有办法修改 project.clj 以告诉它从本地目录中选择一些 jars?
I have some proprietary jars that cannot be uploaded to public repos.
我有一些无法上传到公共存储库的专有 jar。
Also, can leiningen be used to maintain a "lib" directory for clojure projects? If a bunch of my clojure projects share the same jars, I don't want to maintain a separate copy for each of them.
另外,是否可以使用 leiningen 来维护 clojure 项目的“lib”目录?如果我的一堆 clojure 项目共享相同的 jar,我不想为每个项目维护一个单独的副本。
Thanks
谢谢
采纳答案by Micha? Marczyk
You could put your private jars in lib/
and they'd be on the classpath for the purposes of lein swank
and the like; this does seem to defeat the point of using a dependency management tool, though if you don't actually wantthose dependencies managed, you could treat Leiningen as an "open source dependencies management tool" and maybe be careful with lein clean
.
你可以把你的私人罐子放进去lib/
,它们会出于lein swank
诸如此类的目的出现在类路径上;这似乎违背了使用依赖项管理工具的意义,但如果您实际上并不希望管理这些依赖项,您可以将 Leiningen 视为“开源依赖项管理工具”,并且可能要小心使用lein clean
.
As the situation becomes more complex -- there's a larger number of private jars involved, they evolve and you need to take some versioning info on them into account -- Arthur's idea of creating a private Maven repo may be more appropriate.
随着情况变得更加复杂——涉及到更多的私有 jar,它们不断发展,您需要考虑一些关于它们的版本信息——Arthur 创建私有 Maven 存储库的想法可能更合适。
(The HR signifies Leiningen-specific part cut-off point... Continue below for information on the general build / dependency management tooling story in Clojure land, including some links which I think could come in very handy in your situation.)
(HR 表示特定于 Leiningen 的部分截止点......继续下面的信息,了解 Clojure 领域中的一般构建/依赖管理工具故事,包括一些我认为在您的情况下非常有用的链接。)
Also, as of yet, there is no universal agreement on the question of which is the best build tool for Clojure, and Leiningen, while gaining in mindshare, is also constantly gaining in the areas features and polish -- meaning, in particular, that it's not yet complete. Here's a quote from Stuart Halloway, the author of Pragmatic Bookshelf's "Programming Clojure": "My 2c: Leiningen is an important step, but there is still plenty to do." For the full posting and a very interesting discussion re: build tools and the like in Clojure space, see the Leiningen, Clojure and libraries: what am I missing?thread on the Clojure Google group. Many participants specifically mention the need to have local dependencies not contained in any repositories, local or otherwise, and elaborate on the solutions they've come up with for such scenarios. Perhaps you could see if there's anything over there which can solve your problem now / might solve it in the future, when feature sets mature?
此外,到目前为止,对于哪个是 Clojure 的最佳构建工具的问题还没有达成普遍共识,而 Leiningen 在获得思想份额的同时,也在功能和润色方面不断取得进展——这尤其意味着它还没有完成。这是 Pragmatic Bookshelf 的“Programming Clojure”的作者 Stuart Halloway 的一句话:“My 2c: Leiningen 是重要的一步,但仍有很多工作要做。” 有关完整发布和非常有趣的讨论:Clojure 空间中的构建工具等,请参阅Leiningen、Clojure 和库:我错过了什么?Clojure Google 群组上的主题。许多参与者特别提到需要不包含在任何本地或其他存储库中的本地依赖项,并详细说明了他们为此类场景提出的解决方案。也许你可以看看那里是否有什么东西可以现在解决你的问题/将来可能会在功能集成熟时解决它?
Anyway, it is possible that Leiningen may not in fact have a good story ready yet for some complex scenarios. If you feel this may be true of your case (and I mean after you consider the private repo idea), here's some links to maven-based alternatives taken from the above mentioned thread: polyglot maven, clojure-maven-plugin; this blog postingaims to be useful to people trying to use maven with Clojure. As I recall, Meikel Brandmeyer (also on SO under his online handle of kotarak) uses Gradle (a Groovy build system) with a plugin to accomodate Clojure called Clojuresque; I never tried it myself, as don't know the first thing about Groovy, but he claims to run a very nice building act with it and I believe it's got nothing to do with maven -- something which is a plus in and of itself for some of us. :-)
无论如何,莱宁根可能实际上还没有为一些复杂的场景准备好故事。如果您觉得这可能适用于您的情况(我的意思是在您考虑了私人回购的想法之后),这里有一些来自上述线程的基于 maven 的替代方案的链接:polyglot maven, clojure-maven-plugin; 这篇博文旨在对尝试将 maven 与 Clojure 一起使用的人有用。我记得,Meikel Brandmeyer(也在他的 kotarak 在线句柄下的 SO 上)使用 Gradle(一个 Groovy 构建系统)和一个插件来适应 Clojure,称为 Clojuresque;我自己从来没有尝试过,因为不知道 Groovy 的第一件事,但他声称用它运行了一个非常好的构建行为,我相信它与 maven 无关——这本身就是一个加分项对于我们中的一些人。:-)
回答by Arthur Ulfeldt
I believe the "correct" approach is to create a private Maven Repositoryso that you can store the jars in a single location and all your branches etc will pick up the changes. This may be overkill for what your doing. I'm curious if these is an easier way.
我相信“正确”的方法是创建一个私有的 Maven 存储库,以便您可以将 jars 存储在一个位置,并且您的所有分支等都会接收更改。这对于你所做的可能是矫枉过正。我很好奇这些是不是更简单的方法。
回答by Pascal Thivent
Maybe have a look at this previous answer, I provide step by step instructions to setup a repository local to the project (accessed through file://
) in which you could install your jars.
也许看看这个以前的答案,我提供了逐步说明来设置项目本地存储库(通过 访问file://
),您可以在其中安装 jar。
回答by treat your mods well
A recent development is Phil's s3-wagon-private
plugin for Leiningen: https://github.com/technomancy/s3-wagon-private
最近的发展是 Phil 的s3-wagon-private
Leiningen 插件:https: //github.com/technomancy/s3-wagon-private
This should allow you to publish artifacts to a private remote repo.
这应该允许您将工件发布到私有远程存储库。
回答by Janus Troelsen
Create a directory in the project:
mkdir maven_repository
Add local jars to this repository:
For example, this command adds the
jaad-0.8.3.jar
file to the maven repository:mvn deploy:deploy-file -Dfile=jaad-0.8.3.jar -DartifactId=jaad -Dversion=0.8.3 -DgroupId=jaad -Dpackaging=jar -Durl=file:maven_repository
Add the following to
project.clj
:repositories {"local" "file:maven_repository"}
Now a regular
lein deps
should work:$ lein deps Downloading: jaad/jaad/0.8.3/jaad-0.8.3.pom from local Transferring 0K from local [WARNING] *** CHECKSUM FAILED - Error retrieving checksum file for jaad/jaad/0.8.3/jaad-0.8.3.pom - IGNORING
在项目中创建一个目录:
mkdir maven_repository
将本地 jar 添加到此存储库:
例如,此命令将
jaad-0.8.3.jar
文件添加到 maven 存储库:mvn deploy:deploy-file -Dfile=jaad-0.8.3.jar -DartifactId=jaad -Dversion=0.8.3 -DgroupId=jaad -Dpackaging=jar -Durl=file:maven_repository
将以下内容添加到
project.clj
:repositories {"local" "file:maven_repository"}
现在一个常规
lein deps
应该工作:$ lein deps Downloading: jaad/jaad/0.8.3/jaad-0.8.3.pom from local Transferring 0K from local [WARNING] *** CHECKSUM FAILED - Error retrieving checksum file for jaad/jaad/0.8.3/jaad-0.8.3.pom - IGNORING
The warning can be ignored, since the jar will be checked into the project and not downloaded from the internet.
可以忽略警告,因为 jar 将被检入项目而不是从 Internet 下载。
Original source: Using local JAR's with Leiningen(changed since copying)
原始来源:将本地 JAR 与 Leiningen 一起使用(复制后更改)
回答by Shantanu Kumar
You may like to use the plugin lein-localrepo
: https://github.com/kumarshantanu/lein-localrepo
您可能喜欢使用该插件lein-localrepo
:https: //github.com/kumarshantanu/lein-localrepo
回答by Greg B
I find lein pom; lein jar; lein install
works well when developing libraries.
我发现lein pom; lein jar; lein install
在开发库时效果很好。
Do this in the library being developed and your application requiring it will use it without any :repositories
foo required.
在正在开发的库中执行此操作,需要它的应用程序将使用它而无需任何:repositories
foo。
Alternatively, lein do pom, jar, install
is slightly more concise.
或者,lein do pom, jar, install
稍微简洁一些。
This allows calling the library like any other :dependencies [[project-name "version"]]
这允许像任何其他人一样调用库 :dependencies [[project-name "version"]]
回答by Hans-J.
Just use :resource-pathsin your project.clj file. I use it, e.g. to connect to Siebel servers. Just created a resourcesdirectory in my project directory and copied the jar files in there. But of course you could use a more generic directory:
只需在 project.clj 文件中使用:resource-paths 即可。我使用它,例如连接到 Siebel 服务器。刚刚在我的项目目录中创建了一个资源目录并将 jar 文件复制到那里。但当然你可以使用更通用的目录:
(defproject test-project "0.1.0-SNAPSHOT"
:description "Blah blah blah"
...
:resource-paths ["resources/Siebel.jar" "resources/SiebelJI_enu.jar"])
Then from the lein replI can create Siebel Data Bean instances, e.g.
然后从lein repl我可以创建 Siebel Data Bean 实例,例如
(def sbl (com.siebel.data.SiebelDataBean.))
(.login sbl "siebelServer" "user" "password")
...
If you have a newer Java version you can of course use wildcards in your path specification like this for a more general directory:
如果您有更新的 Java 版本,您当然可以在路径规范中使用通配符,如下所示用于更通用的目录:
:resource-paths ["/tmp/SiebelJars/*"]
回答by mike
Try my solution how to build jar file with dependencies http://middlesphere-1.blogspot.ru/2014/06/how-to-make-jar-with-dependencies-using.html
尝试我的解决方案如何构建具有依赖项的 jar 文件 http://middlesphere-1.blogspot.ru/2014/06/how-to-make-jar-with-dependencies-using.html
回答by Roozbeh Zabihollahi
None of these solutions worked me. Instead I have installed a local repository, and used maven to install the jar file in the local repo, and added the local repo to my project.clj
这些解决方案都没有对我有用。相反,我安装了一个本地存储库,并使用 maven 在本地存储库中安装 jar 文件,并将本地存储库添加到我的 project.clj
In command line:
在命令行中:
mvn deploy:deploy-file -DgroupId=local -DartifactId=bar \
-Dversion=1.0.0 -Dpackaging=jar -Dfile=bar.jar \
-Durl=file:repo
And I write my project.clj like this:
我这样写我的 project.clj :
(defproject foo "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.4.0"]
[local/bar "1.0.0"]]
:repositories {"project" "file:repo"})
Hope it helps.
希望能帮助到你。
[REFERENCE: https://gist.github.com/stuartsierra/3062743]