也可以从与斯卡拉文件创建jar文件 [英] Cannot run jar file created from scala file

查看:138
本文介绍了也可以从与斯卡拉文件创建jar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我已经写在斯卡拉code。

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

问题: HELLO-world_2.11-1.0.jar 的已在的目标/斯卡拉2.11 的创建了一个名为jar文件。但我不能运行该文件。这是给我一个错误说的的NoClassDefFoundError

Problem : 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.

问:我在做什么错了?我希望我已经清楚我的问题。如果有一些混乱,那么请询问。先谢谢了。

Question : What am I doing wrong? I hope I have made my question clear. If there is some confusion then please ask. Thanks in advance.

推荐答案

它还说的什么的类没有找到。最有可能你是不包括斯卡拉-library.jar 。您可以运行 Scala的目标/斯卡拉2.11 / HELLO-world_2.11-1.0.jar 如果您有2.11斯卡拉可通过命令行或的java -cp<路径斯卡拉-library.jar>:目标/斯卡拉2.11 / HELLO-world_2.11-1.0.jar主(使用; 来代替在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).

这篇关于也可以从与斯卡拉文件创建jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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