[英]IntelliJ scala project import
I have a scala project in IntelliJ with a simple folder structure src/core/CommonCSVReader.scala
I have a program.scala
file under src/
i run spark-shell from the integrated terminal, and try to run :load program.scala
i get the following error: 我在IntelliJ中有一个带有简单文件夹结构src/core/CommonCSVReader.scala
的scala项目,在src/
下有一个program.scala
文件,我从集成终端运行spark-shell,然后尝试运行:load program.scala
我得到了出现以下错误:
object CommonCSVReader is not a member of package core 对象CommonCSVReader不是包核心的成员
even is i exit spark-shell and try to run scala program.scala
i get the same problem, I wanted to try running the program.scala
from intelliJ but if I right click on program.scala I don't have the Run ScalaApp option, only Run Scala console which just starts a Scala console, I can't find what I'm missing here, thank you, 甚至我退出spark-shell并尝试运行scala program.scala
我也遇到了同样的问题,我想尝试从intelliJ运行program.scala
,但是如果我右键单击program.scala,则没有Run ScalaApp选项,只有运行Scala控制台(仅启动Scala控制台),我在这里找不到我想要的东西,谢谢,
program.scala 程序标量
import core.CommonCSVReader
object program {
def main():Unit = {
val path:String = "some/path"
val reader = new CommonCSVReader(path)
reader.Read()
}
}
EDIT: please find CommonCSVReader Class below: 编辑:请在下面找到CommonCSVReader类:
package core
import org.apache.spark.sql.SparkSession
class CommonCSVReader(filename:String) extends ParserFileReader(filename) {
val spark = SparkSession.builder().config("spark.master",
"local").getOrCreate()
def Read():Unit = {
val df = spark.read.option("header", "true").option("inferSchema",
"true").csv(filename)
//Show Schema
df.printSchema()
}
}
You need to add 您需要添加
package core
to the beginning of CommonCSVReader.scala
. 到CommonCSVReader.scala
的开头。 Just putting it inside the folder isn't enough. 仅将其放在文件夹中是不够的。
Edit: 编辑:
I also just noticed, that you didn't put your packages inside a scala folder. 我也刚刚注意到,您没有将软件包放在scala文件夹中。 The "usual" path is: “常规”路径为:
src/main/scala/<packages>
Though I am not sure if this has an affect or not 虽然我不确定这是否有影响
program.scala
import core.CommonCSVReader
object program extends App {
val path:String = "some/path"
val reader = new CommonCSVReader(path)
reader.Read()
}
it seems I have to extends App, now when I right click on program.scala
I have the option run 'program'
and it works fine, but not from the terminal 似乎我必须扩展App,现在,当我右键单击program.scala
我可以选择run 'program'
,它可以正常运行,但不能从终端运行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.