2013-03-04 83 views
6

我想使用Maven在Eclipse中启动Spark项目。 我已经安装了m2eclipse,并且在我的Maven项目中有一个可用的HelloWorld Java应用程序。如何将Spark添加到Eclipse的Maven项目中?

我想使用Spark框架,我从the official site以下的方向。 我已经添加星火库到我的pom.xml

<repository> 
     <id>Spark repository</id> 
     <url>http://www.sparkjava.com/nexus/content/repositories/spark/</url> 
</repository> 

然后依赖性:

<dependency> 
     <groupId>spark</groupId> 
     <artifactId>spark</artifactId> 
     <version>0.9.9.4-SNAPSHOT</version> 
</dependency> 

但我发现了在Eclipse中的错误:

Missing artifact spark:spark:jar:0.9.9.4-SNAPSHOT 

我怎样才能解决这个问题?我不想下载Spark的jar文件并放置在本地存储库中。

这是我的pom.xml文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.myproject</groupId> 
    <artifactId>Spark1</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>Spark1</name> 
    <url>http://maven.apache.org</url> 

    <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 

    <repository> 
     <id>Spark repository</id> 
     <url>http://www.sparkjava.com/nexus/content/repositories/spark/</url> 
    </repository> 

    <dependencies> 
<!--  (...) --> 

    <dependency> 
     <groupId>spark</groupId> 
     <artifactId>spark</artifactId> 
     <version>0.9.9.4-SNAPSHOT</version> 
    </dependency> 

    </dependencies> 

</project> 
+0

你能告诉我们你的整个'pom.xml'?你可以忽略其他依赖,但我想看看结构。还要确保你的Eclipse项目真的启用了Maven(点击project =>'Configure' =>'Convert to Maven Project')。 – 2013-03-04 21:16:58

+0

@André我已经添加了pom.xml文件来描述。 – beam022 2013-03-04 21:23:14

回答

7

repository块需要被包裹在一个repositories块:

<repositories> 
    <repository> 
     <id>Spark repository</id> 
     <url>http://www.sparkjava.com/nexus/content/repositories/spark/</url> 
    </repository> 
</repositories> 
0

我曾经遇到同样的问题,因为最初我开始用不同存储库URL的火花,然后使用较早的版本我改变了存储库的网址。一些它似乎没有生效,直到我更改存储库ID。尝试更改存储库ID。
可能是maven中的错误,因为从控制台运行maven也无法解决依赖关系而无需更新id。

+0

这实际上对我有效..我所做的只是将id从“Spark repository”更改为“Spark Repository”。 – FSP 2013-05-27 02:47:00

12

目前没有仓库需要增加对星火库加载

你只需要添加

<dependency> 
    <groupId>com.sparkjava</groupId> 
    <artifactId>spark-core</artifactId> 
    <version>2.6.0</version> 
</dependency> 

就是这样。

有用的教程一起玩是here

0

请添加该存储库,标签库标签内像下面

<repositories> 
     <repository> 
      <id>Spark repository</id> 
      <url>http://www.sparkjava.com/nexus/content/repositories/spark/</url> 
     </repository> 
    </repositories> 
5

失败原因是0.9.9.4,快照不是available.Below是可用快照列表。根据您的要求使用其中之一。

0.9.8-SNAPSHOT /周六5月21日21时54分23秒UTC 2011
0.9.9-SNAPSHOT /周一5月23日10时57分38秒UTC 2011
0.9.9.1 - 快照/周四09年5月26日:47:03 UTC 2011
0.9.9.3 - 快照/周四01九月7时53分59秒UTC 2011

感谢, 商羯罗雷迪

0

星火的最后一个版本(2.1及更高版本)只需要在pom中定义的依赖关系。xml文件

<dependency> 
    <groupId>com.sparkjava</groupId> 
    <artifactId>spark-core</artifactId> 
    <version>2.1</version> 
</dependency> 

库定义不再需要

0

使用此功能,并且确保你在Eclipse项目的构建路径改变点火库版本2.11.x

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.spark-scala</groupId> 
    <artifactId>spark-scala</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <name>${project.artifactId}</name> 
    <description>Spark in Scala</description> 
    <inceptionYear>2010</inceptionYear> 

    <properties> 
     <maven.compiler.source>1.8</maven.compiler.source> 
     <maven.compiler.target>1.8</maven.compiler.target> 
     <encoding>UTF-8</encoding> 
     <scala.tools.version>2.10</scala.tools.version> 
     <!-- Put the Scala version of the cluster --> 
     <scala.version>2.10.4</scala.version> 
    </properties> 

    <!-- repository to add org.apache.spark --> 
    <repositories> 
     <repository> 
      <id>cloudera-repo-releases</id> 
      <url>https://repository.cloudera.com/artifactory/repo/</url> 
     </repository> 
    </repositories> 

    <build> 
     <sourceDirectory>src/main/scala</sourceDirectory> 
     <testSourceDirectory>src/test/scala</testSourceDirectory> 
     <plugins> 
      <plugin> 
       <!-- see http://davidb.github.com/scala-maven-plugin --> 
       <groupId>net.alchim31.maven</groupId> 
       <artifactId>scala-maven-plugin</artifactId> 
       <version>3.2.1</version> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <version>2.13</version> 
       <configuration> 
        <useFile>false</useFile> 
        <disableXmlReport>true</disableXmlReport> 
        <includes> 
         <include>**/*Test.*</include> 
         <include>**/*Suite.*</include> 
        </includes> 
       </configuration> 
      </plugin> 

      <!-- "package" command plugin --> 
      <plugin> 
       <artifactId>maven-assembly-plugin</artifactId> 
       <version>2.4.1</version> 
       <configuration> 
        <descriptorRefs> 
         <descriptorRef>jar-with-dependencies</descriptorRef> 
        </descriptorRefs> 
       </configuration> 
       <executions> 
        <execution> 
         <id>make-assembly</id> 
         <phase>package</phase> 
         <goals> 
          <goal>single</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <groupId>org.scala-tools</groupId> 
       <artifactId>maven-scala-plugin</artifactId> 
      </plugin> 
     </plugins> 
    </build> 

    <dependencies> 
     <dependency> 
      <groupId>org.apache.spark</groupId> 
      <artifactId>spark-core_2.11</artifactId> 
      <version>1.2.1</version> 
     </dependency> 
    </dependencies> 
</project> 
相关问题