-1

I am trying to run an application that prints "Hello World!". The script works fine locally, but every time I run it with

:load /path/to/script

output:

    Loading /u/hdpdlcu/Matt/test/SparkScalaCourse/src/com/sundogsoftware/spark/test1.scala...
    defined object test1

I have tried starting it with spark-shell with

spark-shell -i /path/to/script

but that also fails to produce the output "Hello World"

I have tried calling .Main as well.

scala> :load /u/hdpdlcu/Matt/test/SparkScalaCourse/src/com/sundogsoftware/spark/test1.scala Loading /u/hdpdlcu/Matt/test/SparkScalaCourse/src/com/sundogsoftware/spark/test1.scala... defined object test1

scala> /u/hdpdlcu/Matt/test/SparkScalaCourse/src/com/sundogsoftware/spark/test1.Main(Array("a")) :1: error: ';' expected but '.' found. /u/hdpdlcu/Matt/test/SparkScalaCourse/src/com/sundogsoftware/spark/test1.Main(Array("a"))

I tried removing path to file after defining object test1:

scala> :load /u/hdpdlcu/Matt/test/SparkScalaCourse/src/com/sundogsoftware/spark/test1.scala
Loading /u/hdpdlcu/Matt/test/SparkScalaCourse/src/com/sundogsoftware/spark/test1.scala...
defined object test1

scala> test1.main("a")
<console>:26: error: value main is not a member of object test1
       test1.main("a")
             ^

scala> test1.main()
<console>:26: error: value main is not a member of object test1
       test1.main()
             ^

test1.scala:

package com.sundogsoftware.spark

object test1 {

  def Main (args: Array[String]) {
    println("Hello World!")
  }
}
Matt
  • 113
  • 1
  • 1
  • 5
  • *defined object test1*. Seems like it loads the script correctly and without errors. Maybe try something like `test1.main()` and see if it works? – jrook Mar 05 '20 at 18:56
  • It is not working, because there it should be outputting "Hello World." I will update the OP to include contents of test1.scala – Matt Mar 06 '20 at 14:56
  • I have no issues running this code after pasting or `:load test1.scala` and then `test1.Main(Array("a"))` – jrook Mar 06 '20 at 16:53
  • Also relevant: https://stackoverflow.com/questions/9877314/why-is-the-main-function-not-running-in-the-repl – jrook Mar 06 '20 at 16:54
  • OP updated to add more information related to calling the main method. – Matt Mar 06 '20 at 17:47
  • You don't need the full path after the object is defined. Try : `scala > test1.Main("a"))` – jrook Mar 06 '20 at 17:52
  • 1
    calling test1.Main(Array("a")) without pathToScript after running the :load worked. – Matt Mar 06 '20 at 18:12
  • If the linked question also solves your issue, please mark your question as duplicate so people are redirected to the right place. – jrook Mar 06 '20 at 18:31

1 Answers1

0

calling test1.Main(Array("a")) without pathToScript after running the :load worked.

Matt
  • 113
  • 1
  • 1
  • 5