gpt4 book ai didi

java - 如何在 clojure project.clj 中排除storm-core jar

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

I am using Leiningen 2.5.3 on Java 1.7.0_79 OpenJDK 64-Bit Server VM. 

我想使用 lein uberjar 排除storm-core jar。下面是我的项目.clj

(defproject kafka2hdfs "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"]
[org.apache.storm/storm-kafka "0.9.5"]
[org.apache.storm/storm-hdfs "0.9.5"]
[org.apache.kafka/kafka_2.10 "0.8.2.1"]]
:plugins [[cider/cider-nrepl "0.10.0-SNAPSHOT"]]
:target-path "target/%s"
:dev-dependencies [[org.apache.storm/storm-core "0.9.5"]]
:main kafka2hdfs.core
:aot [kafka2hdfs.core])

从 lein uberjar 获取错误输出,如何解决此问题?

$ lein uberjar
Compiling kafka2hdfs.core
java.lang.ClassNotFoundException: backtype.storm.StormSubmitter, compiling:(core.clj:1:1)
Exception in thread "main" java.lang.ClassNotFoundException: backtype.storm.StormSubmitter, compiling:(core.clj:1:1)
at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3463)

我的 core.clj 文件

(ns kafka2hdfs.core
(:import [backtype.storm StormSubmitter LocalCluster spout.SchemeAsMultiScheme]
[storm.kafka ZkHosts SpoutConfig StringScheme KafkaSpout]
[org.apache.storm.hdfs.bolt HdfsBolt]
[org.apache.storm.hdfs.bolt.format DefaultFileNameFormat DelimitedRecordFormat]
[org.apache.storm.hdfs.bolt.sync CountSyncPolicy]
[org.apache.storm.hdfs.bolt.rotation TimedRotationPolicy]
)
(:use [backtype.storm clojure config]) ;; for (topology ...)
(:gen-class))

(defn mk-topology []
;; ......


(topology
{"kafka-reader" (spout-spec kafka-reader :p 2)}
{"hdfs-writer" (bolt-spec {"kafka-reader" :shuffle} hdfs-writer :p 1)})
))

(defn submit-topology! [name]
(StormSubmitter/submitTopology
name
{TOPOLOGY-DEBUG true
TOPOLOGY-WORKERS 3}
(mk-topology)))

(defn -main
"a simple topology demo read from kafka ans write to hdfs"
[& args]
(submit-topology! "kafka2hdfs-topic-bigdata-obd"))

几个小时后,我发现如果我在project.clj中注释掉:aot [kafka2hdfs.core],它可以工作,但会输出警告消息:

$ lein do clean, uberjar
Warning: The Main-Class specified does not exist within the jar. It may not be executable as expected. A gen-class directive may be missing in the namespace which contains the main method.

我是 lein 和 :aot 的新手,为什么?

最佳答案

我不太明白排除 jar 如何解决 ClassNotFoundException,但您可以通过以下方式排除 leiningen 中的传递依赖项


[org.apache.storm/storm-kafka "0.9.5":排除 [org.apache.storm/storm-core]]

看来您的错误原因是缺少 backtype/storm jar。也许您需要从 org.apache.storm 而不是 backtype.storm 导入 :import

关于java - 如何在 clojure project.clj 中排除storm-core jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33478501/

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