gpt4 book ai didi

java - 如何从 Clojure REPL 中的 maven 项目加载 java 类?

转载 作者:行者123 更新时间:2023-11-30 08:20:27 25 4
gpt4 key购买 nike

有谁知道在 Clojure REPL 中从 maven 项目加载 java 类的简单方法?

我看了一下 lein 文档,他们似乎不支持 maven。

clojure-maven-plugin 提供了一个 clojure:repl 目标,但它似乎只是加载项目的依赖项,而不是我的 src/main/java 中的类。

理想情况下,我不愿意只为此任务设置一个 lein 项目,因为我只想玩弄我项目中的一些 Java 类。

有人吗?

最佳答案

lein 支持从 maven 存储库中获取依赖项。事实上,即使不是核心 lein 功能,这也是其中之一。

您可以使用 pallet/alembic获取和加载 maven 依赖项是来自 repl 的运行时。

由于我的 ~/.lein/profiles.clj

中包含以下内容,我可以使用 pallet/alembic
 {:user
{:dependencies [[clojure-complete "0.2.3"]
[lein-pdo "0.1.1"]
[criterium "0.4.2"]
[org.clojure/tools.trace "0.7.6"]
[alembic "0.2.0"]]}}

这意味着我可以在任何 repl 中使用 alembic

user> (require '[alembic.still :as still])
nil
user> (org.apache.giraph.GiraphRunner.) ; create a new GiraphRunner
CompilerException java.lang.ClassNotFoundException: org.apache.giraph.GiraphRunner, compiling:(/tmp/form-init5282725623346658314.clj:1:50)

哎呀,我实际上没有那个类(class)可用

user> (still/distill '[[org.apache.giraph/giraph-core "1.0.0"]] :repositories [["apache" "http://obelix.ics.uci.edu/nexus/content/groups/hyracks-public-releases"]])
WARN: com.google.guava/guava version 12.0 requested, but 14.0.1 already on classpath.
Loaded dependencies:
[[commons-cli "1.2"]
[commons-io "2.1"]
[jline "0.9.94"]
[junit "3.8.1"]
[log4j "1.2.15"]
[com.google.code.findbugs/jsr305 "1.3.9"]
[com.yammer.metrics/metrics-core
"2.2.0"
:exclusions
[[org.slf4j/slf4j-api]]]
[io.netty/netty "3.5.3.Final"]
[it.unimi.dsi/fastutil "6.5.3"]
[javax.activation/activation "1.1"]
[javax.mail/mail "1.4"]
[net.iharder/base64 "2.3.8"]
[org.apache.giraph/giraph-core "1.0.0"]
[org.apache.zookeeper/zookeeper
"3.3.3"
:exclusions
[[com.sun.jmx/jmxri] [com.sun.jdmk/jmxtools] [javax.jms/jms]]]
[org.codehaus.jackson/jackson-core-asl "1.8.0"]
[org.codehaus.jackson/jackson-mapper-asl "1.8.0"]
[org.json/json "20090211"]
[org.slf4j/slf4j-api "1.7.2"]
[org.slf4j/slf4j-log4j12 "1.7.2"]]
Dependencies not loaded due to conflict with previous jars :
[[com.google.guava/guava "12.0"]]
nil

好的,现在我们有了giraph

user> (org.apache.giraph.GiraphRunner.) ; create a new GiraphRunner
CompilerException java.lang.NoClassDefFoundError: org/apache/hadoop/util/Tool, compiling:(/tmp/form-init5282725623346658314.clj:1:50)
user> (still/distill '[[org.apache.hadoop/hadoop-core "0.20.2"]])
WARN: commons-logging version 1.0.3 requested, but 1.1.1 already on classpath.
WARN: commons-codec version 1.3 requested, but 1.6 already on classpath.
Loaded dependencies:
[[ant "1.6.5"]
[commons-cli "1.2"]
[commons-el "1.0"]
[commons-httpclient "3.0.1"]
[commons-net "1.4.1"]
[hsqldb "1.8.0.10"]
[junit "4.5"]
[oro "2.0.8"]
[xmlenc "0.52"]
[net.java.dev.jets3t/jets3t "0.7.1"]
[net.sf.kosmosfs/kfs "0.3"]
[org.apache.hadoop/hadoop-core "0.20.2"]
[org.eclipse.jdt/core "3.1.1"]
[org.mortbay.jetty/jetty "6.1.14"]
[org.mortbay.jetty/jetty-util "6.1.14"]
[org.mortbay.jetty/jsp-2.1 "6.1.14"]
[org.mortbay.jetty/jsp-api-2.1 "6.1.14"]
[org.mortbay.jetty/servlet-api-2.5 "6.1.14"]
[tomcat/jasper-compiler "5.5.12"]
[tomcat/jasper-runtime "5.5.12"]]
Dependencies not loaded due to conflict with previous jars :
[[commons-codec "1.3"] [commons-logging "1.0.3"]]
nil
user> (org.apache.giraph.GiraphRunner.) ; create a new GiraphRunner
#<GiraphRunner org.apache.giraph.GiraphRunner@2dbfe923>
user> (bean *1)
{:conf nil, :class org.apache.giraph.GiraphRunner}

因此,在获取必要的依赖项之后,我们可以通过 maven 存储库创建和试验大多数可用的类。

在您的特定情况下,您可以通过 maven 在本地安装您的 java 项目,然后使用 alembic 将其加载到 repl 中进行实验。

关于java - 如何从 Clojure REPL 中的 maven 项目加载 java 类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26044995/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com