title: read object file from SparkSession in java
body: <p>I have used JavaSparkContext to write a JavaRDD as an object file:</p>
  
  <pre><code>JavaSparkContext sc = new JavaSparkContext(conf); //where conf is a SparkConf
  JavaRDD&lt;MyClass&gt; something;
  something.saveAsObjectFile("path");
  </code></pre>
  
  <p>I can easily load this file using:</p>
  
  <pre><code>JavaRDD&lt;MyClass&gt; loaded = sc.objectFile("path);
  </code></pre>
  
  <p>Now, in the same program, I want to load the object file and also use a SparkSession, in order to create a DataFrame from another file, so I am using:</p>
  
  <pre><code>SparkSession spark = SparkSession.builer()
  .appName("someName")
  .master("local")
  .getOrCreate();
  </code></pre>
  
  <p>Is there any way to load the object file using <code>spark</code>, instead of a JavaSparkContext? </p>
  
  <p>I have tried creating an instance of JavaSparkContext in the same program, but I am getting the error:</p>
  
  <blockquote>
    <p>SparkException: Only one SparkContext may be running in this JVM (see SPARK-2243). </p>
  </blockquote>
  
  <p>I know that SparkSession encapsulates the SparkContext, but how can I do what I want (in Java)? Is there any way to get a JavaSparkContext from a SparkSession? Could I use another way to write the object file using SparkSession instead of JavaSparkContext (I want to save it compressed and not as raw text)?</p>