title: java.net.URISyntaxException: Relative path in absolute URI
body: <p>I need to read a file stored in my project's resources, the directory is <code>src/main/resources/dataset/dataset.dat</code>.
  I'm using the following lines of Scala code to read a text file from HDFS and parse as Spark RDD of dataset objects:</p>
  <pre class="lang-scala prettyprint-override"><code>// init Spark context
  val conf: SparkConf = new SparkConf().setAppName(&quot;mydataset&quot;).setMaster(&quot;local&quot;)
  val sc: SparkContext = new SparkContext(conf)
  
  // read dat file
  val resource = this.getClass.getClassLoader.getResource(&quot;dataset/dataset.dat&quot;)
  val dsRdd: RDD[DatasetObject] = sc.textFile(resource.toString(), 1).map(line =&gt; DatasetData.parse(line))
  </code></pre>
  <p>but the following error occurred:</p>
  <pre><code>class java.lang.IllegalArgumentException: java.net.URISyntaxException: Relative path in absolute URI: jar:file:/grader/grader.jar!/dataset/dataset.dat
  java.lang.IllegalArgumentException: java.net.URISyntaxException: Relative path in absolute URI: jar:file:/grader/grader.jar!/dataset/dataset.dat
  </code></pre>
  <p>I have tried to read the file in another way but the error keeps occurring, e.g.</p>
  <pre><code>val dsRdd: RDD[DatasetObject] = sc.textFile(&quot;src/main/resources/dataset/dataset.dat&quot;).map(line =&gt; DatasetData.parse(line))
  </code></pre>
  <p><strong>Important:</strong> The unit tests are successfully run locally, the problem occurs on the remote test environment.</p>