2015-09-05 12 views
7

私はScalaでSparkを使用するアプリケーションを作成しています。私はMavenを使用してアプリケーションをパッケージ化し、"uber" or "fat" jarを構築するときに問題にぶつかっています。Mavenを使ったScala Sparkプロジェクトのパッケージ化と実行

私が直面している問題は、IDEの内部でアプリケーションを正常に動作させること、またはJavaクラスパスとして依存性の非uber-jarバージョンを提供する場合ですが、

java -Xmx2G -cp target/spark-example-0.1-SNAPSHOT-jar-with-dependencies.jar debug.spark_example.Example data.txt 

は、クラスパスとしてuber jarが動作しません。私は、次のエラーメッセージが表示されます。

ERROR SparkContext: Error initializing SparkContext. 
com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'akka.version' 
    at com.typesafe.config.impl.SimpleConfig.findKey(SimpleConfig.java:124) 
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:145) 
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:151) 
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:159) 
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:164) 
    at com.typesafe.config.impl.SimpleConfig.getString(SimpleConfig.java:206) 
    at akka.actor.ActorSystem$Settings.<init>(ActorSystem.scala:168) 
    at akka.actor.ActorSystemImpl.<init>(ActorSystem.scala:504) 
    at akka.actor.ActorSystem$.apply(ActorSystem.scala:141) 
    at akka.actor.ActorSystem$.apply(ActorSystem.scala:118) 
    at org.apache.spark.util.AkkaUtils$.org$apache$spark$util$AkkaUtils$$doCreateActorSystem(AkkaUtils.scala:122) 
    at org.apache.spark.util.AkkaUtils$$anonfun$1.apply(AkkaUtils.scala:54) 
    at org.apache.spark.util.AkkaUtils$$anonfun$1.apply(AkkaUtils.scala:53) 
    at org.apache.spark.util.Utils$$anonfun$startServiceOnPort$1.apply$mcVI$sp(Utils.scala:1991) 
    at scala.collection.immutable.Range.foreach$mVc$sp(Range.scala:160) 
    at org.apache.spark.util.Utils$.startServiceOnPort(Utils.scala:1982) 
    at org.apache.spark.util.AkkaUtils$.createActorSystem(AkkaUtils.scala:56) 
    at org.apache.spark.rpc.akka.AkkaRpcEnvFactory.create(AkkaRpcEnv.scala:245) 
    at org.apache.spark.rpc.RpcEnv$.create(RpcEnv.scala:52) 
    at org.apache.spark.SparkEnv$.create(SparkEnv.scala:247) 
    at org.apache.spark.SparkEnv$.createDriverEnv(SparkEnv.scala:188) 
    at org.apache.spark.SparkContext.createSparkEnv(SparkContext.scala:267) 
    at org.apache.spark.SparkContext.<init>(SparkContext.scala:424) 
    at debug.spark_example.Example$.main(Example.scala:9) 
    at debug.spark_example.Example.main(Example.scala) 

私はこの作業を取得するためにそれを追加する必要がある理由私はpom.xmlファイルに追加する必要があるとどのような理解を助ける本当にいただければ幸いです。

私はオンラインで検索、私は(ポンポンで参照)しようとした次のリソースを、見つけましたが、仕事を得ることができませんでしいます

1)スパークuserメーリングリスト:http://apache-spark-user-list.1001560.n3.nabble.com/Packaging-a-spark-job-using-maven-td5615.html

2)how to package spark scala application

が、私はこの問題を示し、簡単な例を持っている、シンプルな1クラスのプロジェクト(SRC /メイン/スカラ座/デバッグ/ spark_example/Example.scala):

package debug.spark_example 

import org.apache.spark.{SparkConf, SparkContext} 

object Example { 
    def main(args: Array[String]): Unit = { 
    val sc = new SparkContext(new SparkConf().setAppName("Test").setMaster("local[2]")) 
    val lines = sc.textFile(args(0)) 
    val lineLengths = lines.map(s => s.length) 
    val totalLength = lineLengths.reduce((a, b) => a + b) 
    lineLengths.foreach(println) 
    println(totalLength) 
    } 
} 
あなたの助けを事前に

<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>debug.spark-example</groupId> 
    <artifactId>spark-example</artifactId> 
    <version>0.1-SNAPSHOT</version> 
    <inceptionYear>2015</inceptionYear> 
    <properties> 
    <scala.majorVersion>2.11</scala.majorVersion> 
    <scala.minorVersion>.2</scala.minorVersion> 
    <spark.version>1.4.1</spark.version> 
    </properties> 


    <repositories> 
    <repository> 
     <id>scala-tools.org</id> 
     <name>Scala-Tools Maven2 Repository</name> 
     <url>http://scala-tools.org/repo-releases</url> 
    </repository> 
    </repositories> 

    <pluginRepositories> 
    <pluginRepository> 
     <id>scala-tools.org</id> 
     <name>Scala-Tools Maven2 Repository</name> 
     <url>http://scala-tools.org/repo-releases</url> 
    </pluginRepository> 
    </pluginRepositories> 

    <dependencies> 
    <dependency> 
     <groupId>org.scala-lang</groupId> 
     <artifactId>scala-library</artifactId> 
     <version>${scala.majorVersion}${scala.minorVersion}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.spark</groupId> 
     <artifactId>spark-core_${scala.majorVersion}</artifactId> 
     <version>${spark.version}</version> 
    </dependency> 
    </dependencies> 


    <build> 
     <sourceDirectory>src/main/scala</sourceDirectory> 
     <plugins> 
     <plugin> 
      <groupId>org.scala-tools</groupId> 
      <artifactId>maven-scala-plugin</artifactId> 
      <executions> 
      <execution> 
       <goals> 
       <goal>compile</goal> 
       <goal>testCompile</goal> 
       </goals> 
      </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-eclipse-plugin</artifactId> 
     <configuration> 
     <downloadSources>true</downloadSources> 
     <buildcommands> 
      <buildcommand>ch.epfl.lamp.sdt.core.scalabuilder</buildcommand> 
     </buildcommands> 
     <additionalProjectnatures> 
      <projectnature>ch.epfl.lamp.sdt.core.scalanature</projectnature> 
     </additionalProjectnatures> 
     <classpathContainers> 
      <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer> 
      <classpathContainer>ch.epfl.lamp.sdt.launching.SCALA_CONTAINER</classpathContainer> 
     </classpathContainers> 
     </configuration> 
    </plugin> 
    <plugin> 
     <artifactId>maven-assembly-plugin</artifactId> 
     <version>2.4</version> 
     <executions> 
     <execution> 
      <id>make-assembly</id> 
      <phase>package</phase> 
      <goals> 
      <goal>attached</goal> 
      </goals> 
     </execution> 
     </executions> 
     <configuration> 
     <tarLongFileMode>gnu</tarLongFileMode> 
     <descriptorRefs> 
      <descriptorRef>jar-with-dependencies</descriptorRef> 
     </descriptorRefs> 
     </configuration> 
    </plugin> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-shade-plugin</artifactId> 
     <version>2.2</version> 
     <executions> 
     <execution> 
      <phase>package</phase> 
      <goals> 
      <goal>shade</goal> 
      </goals> 
      <configuration> 
      <minimizeJar>false</minimizeJar> 
      <createDependencyReducedPom>false</createDependencyReducedPom> 
      <artifactSet> 
       <includes> 
       <!-- Include here the dependencies you want to be packed in your fat jar --> 
       <include>*:*</include> 
       </includes> 
      </artifactSet> 
      <filters> 
       <filter> 
       <artifact>*:*</artifact> 
       <excludes> 
        <exclude>META-INF/*.SF</exclude> 
        <exclude>META-INF/*.DSA</exclude> 
        <exclude>META-INF/*.RSA</exclude> 
       </excludes> 
       </filter> 
      </filters> 
      <transformers> 
       <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 
       <resource>reference.conf</resource> 
       </transformer> 
      </transformers> 
      </configuration> 
     </execution> 
     </executions> 
    </plugin> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-surefire-plugin</artifactId> 
     <version>2.7</version> 
     <configuration> 
     <skipTests>true</skipTests> 
     </configuration> 
    </plugin> 
    </plugins> 
</build> 
<reporting> 
    <plugins> 
    <plugin> 
     <groupId>org.scala-tools</groupId> 
     <artifactId>maven-scala-plugin</artifactId> 
    </plugin> 
    </plugins> 
</reporting> 
</project> 

感謝:

はここでpom.xmlファイルです。

+0

詳細を教えてください。 – Holden

+0

@Holden質問に表示されるエラーメッセージを追加しました。これを見てくれてありがとう! – br19

+0

シェードのAkka指示を調べましたか?http://doc.akka.io/docs/akka/snapshot/general/configuration.html – Edmon

答えて

0

これは、あなたのMavenプラグインの順序と関係があるかもしれません。あなたのプロジェクトには、メンブレンライフサイクルの同じフェーズにバインドされた "maven-assembly-plugin"と "maven-shade-plugin"プラグインの両方を使用しています。これが起こると、mavenはプラグインセクションに表示される順番でプラグインを実行します。その場合は、アセンブリプラグインを実行し、次にシェードプラグインを実行します。

実行しようとしている出力jarと、あなたが持っている陰影変換に基づいて、逆の順序が必要です。ただし、ユースケースに合わせてアセンブリプラグインが必要ない場合もあります。 target/spark-example-0.1-SNAPSHOT-shaded.jarファイルを使用することができます。

<plugins> 
    <plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-shade-plugin</artifactId> 
    <!-- SNIP --> 
    </plugin> 
    <plugin> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <!-- SNIP --> 
    </plugin> 
</plugins> 
+0

答えてくれてありがとうございます。私はまだこれを動作させるのに問題があります。私はプラグインの順序を逆にして、陰影のついた瓶を使ってみました。注文を元に戻してもユーバージャーは変わらなかった。影付きのjarを使用すると、エラーメッセージは次のようになります。 'akka.ConfigurationException:タイプ[akka.dispatch.BoundedControlAwareMessageQueueSemantics]がakka.actor.mailbox.requirement [akka.actor.mailbox.bounded-control-aware-queue-based] [akka.dispatch.BoundedControlAwareMessageQueueSemantics] ' – br19

3

プログラムを実行するために使用されなければならないスパークは、スクリプトを提出しているようです。

むしろより:

java -Xmx2G -cp target/spark-example-0.1-SNAPSHOT-jar-with-dependencies.jar debug.spark_example.Example data.txt 

ような何かを:またのない日陰のjarを動作するようです

<path-to>/spark-1.4.1/bin/spark-submit --class debug.spark_example.Example --master local[2] target/spark-example-0.1-SNAPSHOT-jar-with-dependencies.jar data.txt 

。依存関係のある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/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>debug.spark-example</groupId> 
    <artifactId>spark-example</artifactId> 
    <version>0.1-SNAPSHOT</version> 
    <inceptionYear>2015</inceptionYear> 
    <properties> 
     <scala.majorVersion>2.11</scala.majorVersion> 
     <scala.minorVersion>.2</scala.minorVersion> 
     <spark.version>1.4.1</spark.version> 
    </properties> 
    <repositories> 
     <repository> 
      <id>scala-tools.org</id> 
      <name>Scala-Tools Maven2 Repository</name> 
      <url>http://scala-tools.org/repo-releases</url> 
     </repository> 
    </repositories> 
    <pluginRepositories> 
     <pluginRepository> 
      <id>scala-tools.org</id> 
      <name>Scala-Tools Maven2 Repository</name> 
      <url>http://scala-tools.org/repo-releases</url> 
     </pluginRepository> 
    </pluginRepositories> 
    <dependencies> 
     <dependency> 
      <groupId>org.scala-lang</groupId> 
      <artifactId>scala-library</artifactId> 
      <version>${scala.majorVersion}${scala.minorVersion}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.spark</groupId> 
      <artifactId>spark-core_${scala.majorVersion}</artifactId> 
      <version>${spark.version}</version> 
     </dependency> 
    </dependencies> 
    <build> 
     <sourceDirectory>src/main/scala</sourceDirectory> 
     <plugins> 
      <plugin> 
       <groupId>org.scala-tools</groupId> 
       <artifactId>maven-scala-plugin</artifactId> 
       <executions> 
        <execution> 
         <goals> 
          <goal>compile</goal> 
          <goal>testCompile</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-eclipse-plugin</artifactId> 
       <configuration> 
        <downloadSources>true</downloadSources> 
        <buildcommands> 
         <buildcommand>ch.epfl.lamp.sdt.core.scalabuilder</buildcommand> 
        </buildcommands> 
        <additionalProjectnatures> 
         <projectnature>ch.epfl.lamp.sdt.core.scalanature</projectnature> 
        </additionalProjectnatures> 
       <classpathContainers> 
        <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer> 
        <classpathContainer>ch.epfl.lamp.sdt.launching.SCALA_CONTAINER</classpathContainer> 
       </classpathContainers> 
       </configuration> 
      </plugin> 
      <plugin> 
       <artifactId>maven-assembly-plugin</artifactId> 
       <version>2.4</version> 
       <executions> 
       <execution> 
        <id>make-assembly</id> 
        <phase>package</phase> 
        <goals> 
         <goal>attached</goal> 
        </goals> 
       </execution> 
      </executions> 
      <configuration> 
       <tarLongFileMode>gnu</tarLongFileMode> 
       <descriptorRefs> 
        <descriptorRef>jar-with-dependencies</descriptorRef> 
       </descriptorRefs> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.7</version> 
      <configuration> 
       <skipTests>true</skipTests> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 
<reporting> 
    <plugins> 
     <plugin> 
      <groupId>org.scala-tools</groupId> 
      <artifactId>maven-scala-plugin</artifactId> 
     </plugin> 
    </plugins> 
</reporting> 
</project> 
0

Akka Docs私は問題を解決する助けました。Shadeを使用している場合は、変圧器を指定する必要があります。

      <transformer 
            implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 
           <resource>reference.conf</resource> 
          </transformer> 
          <transformer 
            implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
           <manifestEntries> 
            <Main-Class>akka.Main</Main-Class> 
           </manifestEntries> 
          </transformer> 
+0

のため、設定でロードできませんでした。私はこれを試してみる – br19

関連する問題