简体   繁体   English

Scalatra 找不到或无法加载主类

[英]Scalatra could not find or load main class

I have hello world scalatra application.我有 hello world scalatra 应用程序。 I added scalatra-sbt plugin and:我添加了 scalatra-sbt 插件和:

val myDistSettings = DistPlugin.distSettings ++ Seq(
    mainClass in Dist := Some("WebServerLauncher"),
    memSetting in Dist := "2g",
    permGenSetting in Dist := "256m",
    envExports in Dist := Seq("LC_CTYPE=en_US.UTF-8", "LC_ALL=en_US.utf-8"),
    javaOptions in Dist ++= Seq("-Xss4m",
      "-Dfile.encoding=UTF-8",
      "-Dlogback.configurationFile=logback.prod.xml",
      "-Dorg.scalatra.environment=production")
  )

After making sbt dist it generates .zip with:制作sbt dist它会生成 .zip 文件:

#!/bin/env bash

export CLASSPATH="lib:lib/logback-core-1.0.6.jar:lib/jetty-webapp-8.1.8.v20121106.jar:lib/jetty-io-8.1.8.v20121106.jar:lib/scalatra-scalate_2.10-2.2.2.jar:lib/jetty-server-8.1.8.v20121106.jar:lib/mime-util-2.1.3.jar:lib/scalatra-common_2.10-2.2.2.jar:lib/scalate-core_2.10-1.6.1.jar:lib/jetty-util-8.1.8.v20121106.jar:lib/jetty-servlet-8.1.8.v20121106.jar:lib/joda-convert-1.2.jar:lib/juniversalchardet-1.0.3.jar:lib/slf4j-api-1.7.5.jar:lib/scala-library-2.10.4.jar:lib/jetty-continuation-8.1.8.v20121106.jar:lib/grizzled-slf4j_2.10-1.0.1.jar:lib/config-1.0.0.jar:lib/javax.servlet-3.0.0.v201112011016.jar:lib/jetty-xml-8.1.8.v20121106.jar:lib/rl_2.10-0.4.4.jar:lib/jetty-security-8.1.8.v20121106.jar:lib/akka-actor_2.10-2.1.2.jar:lib/jetty-http-8.1.8.v20121106.jar:lib/scala-reflect-2.10.0.jar:lib/scalate-util_2.10-1.6.1.jar:lib/logback-classic-1.0.6.jar:lib/scalatra_2.10-2.2.2.jar:lib/joda-time-2.2.jar:lib/scala-compiler-2.10.0.jar:"
export JAVA_OPTS="-Xms2g -Xmx2g -XX:PermSize=256m -XX:MaxPermSize=256m -Xss4m -Dfile.encoding=UTF-8 -Dlogback.configurationFile=logback.prod.xml -Dorg.scalatra.environment=production"
export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.utf-8

java $JAVA_OPTS -cp $CLASSPATH WebServerLauncher

When i'm trying to run it i got:当我尝试运行它时,我得到了:

Error: Could not find or load main class WebServerLauncher

There is WebServerLauncher.class in lib directory. lib 目录中有WebServerLauncher.class

How to correctly launch it?如何正确启动它?

Thank you.谢谢你。

I was having the exact same problem today.我今天遇到了完全相同的问题。

What I found is that the generated script is path-dependent.我发现生成的脚本是路径相关的。 That is, you do NOT execute it from within the bin directory, but one directory higher, in dist.也就是说,您不是在 bin 目录中执行它,而是在更高的目录 dist 中执行它。

You then execute bin/YOURSCRIPTNAME and it should work.然后您执行 bin/YOURSCRIPTNAME ,它应该可以工作。

I figured this out when I noticed that the path for the CLASSLIB weas lib/WHATEVER (relative path).当我注意到 CLASSLIB 的路径是 lib/WHATEVER(相对路径)时,我发现了这一点。 The only place this path would be correct would be from the dist directory.这个路径唯一正确的地方是来自 dist 目录。

Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM