2017-01-14 149 views
1

导入包org.apache.spark.Row时,收到错误“object Row不是包org.apache.spark的成员”。 我按照教程创建了一个maven项目。通过添加下面的内容更新POM.xml。我错过任何文件吗?导入包导入时出错org.apache.spark.Row

<dependencies> 
     <dependency> 
      <groupId>org.apache.spark</groupId> 
      <artifactId>spark-core_2.10</artifactId> 
      <version>1.6.0</version> 
     </dependency> 
     <!-- https://mvnrepository.com/artifact/org.apache.spark/spark-streaming-kafka_2.10 --> 
     <dependency> 
      <groupId>org.apache.spark</groupId> 
      <artifactId>spark-streaming-kafka_2.10</artifactId> 
      <version>1.6.0</version> 
     </dependency> 
     <!-- https://mvnrepository.com/artifact/org.apache.spark/spark-streaming_2.10 --> 
     <dependency> 
      <groupId>org.apache.spark</groupId> 
      <artifactId>spark-streaming_2.10</artifactId> 
      <version>1.6.0</version> 
     </dependency> 
     <!-- https://mvnrepository.com/artifact/org.apache.kafka/kafka_2.10 --> 
     <dependency> 
      <groupId>org.apache.kafka</groupId> 
      <artifactId>kafka_2.10</artifactId> 
      <version>0.8.2.1</version> 
     </dependency> 

    </dependencies> 

    <build> 
     <plugins> 
      <!-- mixed scala/java compile --> 
      <plugin> 
       <groupId>org.scala-tools</groupId> 
       <artifactId>maven-scala-plugin</artifactId> 
       <executions> 
        <execution> 
         <id>compile</id> 
         <goals> 
          <goal>compile</goal> 
         </goals> 
         <phase>compile</phase> 
        </execution> 
        <execution> 
         <id>test-compile</id> 
         <goals> 
          <goal>testCompile</goal> 
         </goals> 
         <phase>test-compile</phase> 
        </execution> 
        <execution> 
         <phase>process-resources</phase> 
         <goals> 
          <goal>compile</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <configuration> 
        <source>1.7</source> 
        <target>1.7</target> 
       </configuration> 
      </plugin> 
      <!-- for fatjar --> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-assembly-plugin</artifactId> 
       <version>2.4</version> 
       <configuration> 
        <descriptorRefs> 
         <descriptorRef>jar-with-dependencies</descriptorRef> 
        </descriptorRefs> 
       </configuration> 
       <executions> 
        <execution> 
         <id>assemble-all</id> 
         <phase>package</phase> 
         <goals> 
          <goal>single</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-jar-plugin</artifactId> 
       <configuration> 
        <archive> 
         <manifest> 
          <addClasspath>true</addClasspath> 
          <mainClass>fully.qualified.MainClass</mainClass> 
         </manifest> 
        </archive> 
       </configuration> 
      </plugin> 
     </plugins> 
     <pluginManagement> 
      <plugins> 
       <!--This plugin's configuration is used to store Eclipse m2e settings 
        only. It has no influence on the Maven build itself. --> 
       <plugin> 
        <groupId>org.eclipse.m2e</groupId> 
        <artifactId>lifecycle-mapping</artifactId> 
        <version>1.0.0</version> 
        <configuration> 
         <lifecycleMappingMetadata> 
          <pluginExecutions> 
           <pluginExecution> 
            <pluginExecutionFilter> 
             <groupId>org.scala-tools</groupId> 
             <artifactId> 
              maven-scala-plugin 
             </artifactId> 
             <versionRange> 
              [2.15.2,) 
             </versionRange> 
             <goals> 
              <goal>compile</goal> 
              <goal>testCompile</goal> 
             </goals> 
            </pluginExecutionFilter> 
            <action> 
             <execute></execute> 
            </action> 
           </pluginExecution> 
          </pluginExecutions> 
         </lifecycleMappingMetadata> 
        </configuration> 
       </plugin> 
      </plugins> 
     </pluginManagement> 
    </build> 
+0

行是'org.apache.spark.sql'类。您需要执行'import org.apache.spark.sql.Row' –

回答

0

请在你的pom.xml

<!-- https://mvnrepository.com/artifact/org.apache.spark/spark-sql_2.10 --> 
<dependency> 
    <groupId>org.apache.spark</groupId> 
    <artifactId>spark-sql_2.10</artifactId> 
    <version>1.6.0</version> 
</dependency> 

交叉检查的火花核心和火花SQL的版本应该是相同的添加以下的依赖。

import org.apache.spark.sql.Row 

这应该有效。

+1

Hi Rajat,您提供的解决方案有效。 –