【问题标题】:Scala-Redis library is not included in the fat jar fileScala-Redis 库不包含在 fat jar 文件中
【发布时间】:2015-02-24 12:19:26
【问题描述】:

我正在开发一个更新 Redis 服务器的 scala 独立应用程序(将此应用程序作为 Spark 作业执行)。我的应用程序的 Scala 版本是 2.10。

我正在使用 "net.debasishg" % "redisclient_2.10" % "2.13" 来处理 Redis 服务器。

我通过 IntelliJ idea 运行了应用程序,并且应用程序正在运行,没有任何错误。然后我通过给出“激活器包”命令创建我的应用程序的一个 jar。然后我执行jar文件,报错如下,

Exception in thread "main" java.lang.NoClassDefFoundError: com/redis/RedisClient
at Main$.main(Main.scala:55)
at Main.main(Main.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.apache.spark.deploy.SparkSubmit$.launch(SparkSubmit.scala:328)
at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:75)
at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala) 
Caused by: java.lang.ClassNotFoundException: com.redis.RedisClient
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 9 more

请任何人知道如何克服这个问题。 (不幸的是,我尝试使用 sbt-assembly 插件并没有解决我的问题)

谢谢

【问题讨论】:

    标签: scala redis executable-jar


    【解决方案1】:

    我已经解决了这个问题,

    1. 创建一个 assembly.sbt 文件并添加到应用程序的项目目录中。此文件包含 "org.apache.spark" %% "spark-core" % "1.0.0" 插件。

    2. 在 build.sbt 文件中添加了以下几行

      scalaVersion := "2.10.4"

      libraryDependencies ++= Seq(
       "org.scalatest" %% "scalatest" % "2.1.6" % "test",
       ("org.apache.spark" %% "spark-core" % "1.0.0").
        exclude("org.eclipse.jetty.orbit", "javax.servlet").
        exclude("org.eclipse.jetty.orbit", "javax.transaction").
        exclude("org.eclipse.jetty.orbit", "javax.mail").
        exclude("org.eclipse.jetty.orbit", "javax.activation").
        exclude("commons-beanutils", "commons-beanutils-core").
        exclude("commons-collections", "commons-collections").
        exclude("commons-collections", "commons-collections").
        exclude("com.esotericsoftware.minlog", "minlog"),
       ("org.apache.hadoop" % "hadoop-client" % " 2.2.0").
        exclude("com.twitter", "parquet-column"),
       "org.apache.spark" % "spark-sql_2.10" % "1.2.0",
       "org.apache.spark" % "spark-hive_2.10" % "1.2.0",
       "net.debasishg" % "redisclient_2.10" % "2.14"
       excludeAll(
        ExclusionRule(organization = "org.slf4j"),
        ExclusionRule(organization = "com.twitter")
       ) 
      )
      
      mergeStrategy in assembly <<= (mergeStrategy in assembly) { (old) => {
        case PathList("javax", "servlet", xs@_*) => MergeStrategy.first
        case PathList(ps@_*) if ps.last endsWith ".html" => MergeStrategy.first
        case PathList(ps@_*) if ps.last endsWith ".properties" => MergeStrategy.first
        case PathList(ps@_*) if ps.last endsWith ".xml" => MergeStrategy.first
        case PathList(ps@_*) if ps.last endsWith ".class" => MergeStrategy.first
        case PathList(ps@_*) if ps.last endsWith ".thrift" => MergeStrategy.first
        case "application.conf" => MergeStrategy.concat
        case "unwanted.txt" => MergeStrategy.discard
        case x => old(x)
       }
      }
      
    3. 最后用“activator clean”命令清理应用程序,然后运行“activator assembly”打包项目

    谢谢

    【讨论】:

      猜你喜欢
      • 2020-09-04
      • 2017-04-06
      • 2018-11-26
      • 2010-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-21
      • 2020-08-06
      相关资源
      最近更新 更多