I am trying to create a Spark application running on Scala that reads a .csv
file that is located in src/main/resources
directory and saves it on the local hdfs
instance. Everything works charming when I run it locally, whenever I bundle it as a .jar file however and deploy it on a server something goes wrong...
This is my code that that is located in src/main/scala
, the location of my datafile is src/main/resources/dataset.csv
:
val df = spark.read
.format("csv")
.option("header", "true")
.option("inferSchema", "true")
.load(getClass.getResource("dataset.csv").toString())
When I make a jar by calling sbt package
and deploy this to my server however, I receive the following error:
Exception in thread "main" java.lang.IllegalArgumentException:
java.net.URISyntaxException:
Relative path in absolute URI: jar:file:/root/./myapp_2.11-0.1.jar!/dataset.csv
How can I correctly link to my file?