无法运行从 Scala 文件创建的 jar 文件 [英] Cannot run jar file created from Scala file

查看:24
本文介绍了无法运行从 Scala 文件创建的 jar 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我用 Scala 编写的代码.

This the code that I have written in Scala.

object Main extends App {
    println("Hello World from Scala!")
}

这是我的build.sbt.

name := "hello-world"
version := "1.0"
scalaVersion := "2.11.5"
mainClass := Some("Main")

这是我用来创建 jar 文件的命令.

This is the command that I have run to create the jar file.

sbt package

我的问题是在 target/scala-2.11 上创建了一个名为 hello-world_2.11-1.0.jar 的 jar 文件.但我无法运行该文件.它给我一个错误,说 NoClassDefFoundError.

My problem is that a jar file named hello-world_2.11-1.0.jar has been created at target/scala-2.11. But I cannot run the file. It is giving me an error saying NoClassDefFoundError.

我做错了什么?

推荐答案

它还说明什么没有找到类.很可能您没有包含 scala-library.jar.你可以运行 scala target/scala-2.11/hello-world_2.11-1.0.jar 如果你从命令行或 java -cp "<path to scala-library.jar>:target/scala-2.11/hello-world_2.11-1.0.jar" Main (在 Windows 上使用 ; 而不是 : ).

It also says what class is not found. Most likely you aren't including scala-library.jar. You can run scala target/scala-2.11/hello-world_2.11-1.0.jar if you have Scala 2.11 available from the command line or java -cp "<path to scala-library.jar>:target/scala-2.11/hello-world_2.11-1.0.jar" Main (use ; instead of : on Windows).

这篇关于无法运行从 Scala 文件创建的 jar 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆