【问题标题】:sbt run works fine but running jar failssbt run 工作正常,但运行 jar 失败
【发布时间】:2018-09-24 08:58:06
【问题描述】:

当我从 sbt 运行时

(sbt 运行)

我的 akka http 服务运行良好,但是使用 jar 运行时出现以下错误

(java -jar myservice.jar)

由 publishLocal 创建

(sbt publishLocal)

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    at com.rogers.profileauthn.StartProfileAuthService.<clinit>(StartProfileAuthService.java:15)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

sbt 文件中的依赖关系如下

val akkaVersion = "2.5.11"
val akkaHttpVersion = "10.0.11"
libraryDependencies ++= Seq(
  "ch.qos.logback" % "logback-classic" % "1.2.3",
  "com.typesafe.akka" %% "akka-http"            % akkaHttpVersion,
  "com.typesafe.akka" %% "akka-stream"          % akkaVersion,
  "com.typesafe.akka" %% "akka-http-jackson"    % akkaHttpVersion,
  "com.typesafe.akka" %% "akka-http-testkit" % akkaHttpVersion % Test,
  "com.typesafe.akka" %% "akka-testkit" % akkaVersion % Test,
  "junit"              % "junit"             % "4.12"          % Test,
  "com.novocode"       % "junit-interface"   % "0.10"          % Test,
  "com.typesafe.play" %% "play-json" % "2.6.9",
  "com.github.swagger-akka-http" %% "swagger-akka-http" % "0.11.0",
  "com.google.inject" % "guice" % "4.1.0",
  "com.google.guava" % "guava" % "18.0",
  "org.mockito" % "mockito-core" % "2.11.0"

)

我正在使用的记录器如下

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
...
private static final Logger LOGGER = LoggerFactory.getLogger(StartService.class);
    LOGGER.info("**** StartService.createAndStartActorSystem Starts ****");

【问题讨论】:

    标签: java scala sbt akka akka-http


    【解决方案1】:

    我认为那是因为 jar 没有与您的依赖项一起打包。你可以尝试用 sbt 程序集创建一个胖罐子吗? https://github.com/sbt/sbt-assembly。 publishLocal 命令用于部署到 ivy 存储库,而不是像我相信的那样创建 jar 来运行。 (添加插件并运行 sbt 程序集)

    【讨论】:

      猜你喜欢
      • 2014-02-13
      • 2018-09-19
      • 1970-01-01
      • 2021-09-05
      • 2015-10-22
      • 2019-02-23
      • 2019-02-03
      • 2015-01-25
      • 2020-02-04
      相关资源
      最近更新 更多