sbt运行正常但运行jar失败

时间:2018-04-13 23:45:37

标签: java scala sbt akka akka-http

我从sbt

运行
  

sbt run

我的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 ****");

1 个答案:

答案 0 :(得分:1)

我认为那是因为jar没有与你的依赖包装在一起。你能尝试用sbt组装创建一个胖罐吗? https://github.com/sbt/sbt-assembly。 publishLocal命令用于部署到常春藤存储库,而不是创建像我认为的那样运行的jar。 (添加插件并运行sbt程序集)