gpt4 book ai didi

scala - 将 Scala 应用程序作为 Java 应用程序运行

转载 作者:行者123 更新时间:2023-12-04 06:27:54 25 4
gpt4 key购买 nike

我正在尝试运行以下火箭发射应用程序:

object HelloWorld {
def main(args: Array[String]) {
println("Hello World!")
}
}

直接从 java 像这样:
java -cp scala-library.jar HelloWorld

(显然在与 Scala 合规之后)

但得到以下错误:
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
Caused by: java.lang.ClassNotFoundException: HelloWorld
at java.net.URLClassLoader$1.run(Unknown Source)
(...)
Could not find the main class: HelloWorld. Program will exit.

我是否监督过任何我需要做的琐碎事情才能使其发挥作用?

最佳答案

来自 Java documentation :

The default class path is the current directory. Setting the CLASSPATH variable or using the -classpath command-line option overrides that default, so if you want to include the current directory in the search path, you must include "." in the new settings.



添加 .: (或 .; 在 Windows 上)到类路径的开头应该可以工作。

关于scala - 将 Scala 应用程序作为 Java 应用程序运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3487591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com