‘壹’ 怎么用Eclipse搭建Spark源码阅读环境
第一部分、软件安装
1、 安装JDK (版本为1.7.0_11)
2、 安装Scala (版本为2.11.2)
3、 安装ScalaIDE(版本为3.0.4)
第二部分:加压缩官网下载的源代码包或者找到通过Git抽取的Spark源文件:
我用的是spark-1.1.1版本(最新版本),由于idea 13已经原生支持sbt,所以无须为idea安装sbt插件。
源码下载(用git工具):
# Masterdevelopment branch
gitclone git://github.com/apache/spark.git
# 1.1 maintenancebranch with stability fixes on top of Spark 1.1.1
gitclone git://github.com/apache/spark.git -b branch-1.1
源码更新(用git工具同步跟新源码):
gitclone https://github.com/apache/spark.git
第三部分:通过sbt工具,构建Scala的Eclipse工程,详细步骤如下所示
1、通过cmd命令进入DOS界面,之后通过cd命令进入源代码项目中,我下载的Spark.1.1.1版本的源代码放在(E:\Spark计算框架的研究\spark_1_1_1_eclipse)文件夹中,之后运行sbt命令,如下所示:
2、运行sbt命令之后,解析编译相关的jar包,并出现sbt命令界面窗口,出现的效果图如下所示,之后运行eclipse命令,sbt对这个工程进行编译,构建Eclipse项目,效果图如下所示:
4、 打开ScalaIDE工具,File à Import à Existing Projects into Workspace à
Next à
选择刚好用sbt工具编译好的Eclipse工程(E:\Spark计算框架的研究\spark_1_1_1_eclipse),如下图所示。
5、 通过上面的操作,就可以将通过sbt工具编译生成的Eclipse项目导入到EclipseIDE开发环境中,效果图如下所示:
错误提示如下所示:我导入的包为,如下文件夹中所示。
(E:\Spark计算框架的研究\spark_1_1_1_eclipse\lib_managed\bundles)
Description Resource Path Location Type
akka-remote_2.10-2.2.3-shaded-protobuf.jar is cross-compiled
with an incompatible version of Scala (2.10).
In case of errorneous report, this check can be disabled
in the compiler preference page.
spark-core Unknown Scala Classpath Problem
Description Resource Path Location Type
akka-slf4j_2.10-2.2.3-shaded-protobuf.jar is cross-compiled with
an incompatible version of Scala (2.10). In case of errorneous report,
this check can be disabled in the compiler preference page.
spark-core Unknown Scala Classpath Problem
Description Resource Path Location Type
akka-testkit_2.10-2.2.3-shaded-protobuf.jar is cross-compiled
with an incompatible version of Scala (2.10).
In case of errorneous report, this check can be disabled in the compiler preference page.
spark-core Unknown Scala Classpath Problem
Description Resource Path Location Type
akka-zeromq_2.10-2.2.3-shaded-protobuf.jar is cross-compiled
with an incompatible version of Scala (2.10).
In case of errorneous report, this check can be disabled in the compiler preference page.
spark-core Unknown Scala Classpath Problem
上面这些包兼容性问题还没有解决,修改相应的jar包就可以解决。
‘贰’ 如何配置sbt的build.sbt使得编译时将依赖包也打包进去
首先问题解决了,就是sbt-assembly插件的配置问题。这个文档自己前两次读表示看不懂意思。过2天又仔细看了一遍大致明白了,敢动手操作了。
assembly插件的目的是:
The goal is simple: Create a fat JAR of your project with all of its dependencies.
即将项目依赖的大文件也打包到生成的jar中。我的报错Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/spark/streaming/kafka/KafkaUtils$就是因为包含KafkaUtil的jar包没打包到jar中。
配置使用插件
下面是我的scala项目目录结构:
.
├── assembly.sbt
├── build.sbt
├── project
├── README.md
├── run-assembly.sh
├── run.sh
├── src
└── target
插件的配置取决于sbt的版本,详情见这里
我的是sbt 0.13.8,所以在project/assembly.sbt添加(assembly.sbt)要自己创建:
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.0")
配置assembly的参数
参数在项目根目录下新建assembly.sbt。
直接引入插件就可以用
sbt assembly
编译了,但是由于我的sbt下载了大量的依赖包,在编译的时候遇到了编译包冲突的问题。这个时候需要配置Merge Strategy(合并策略)
‘叁’ cassandra在pom.xml里面怎么设置library
1.执行代码//CassandraTest.scalaimportorg.apache.spark.{Logging,SparkContext,SparkConf}importcom.datastax.spark.connector.cql.{defmain(args:Array[String]){#配置spark,cassandra的ip,这里都是本机valSparkMasterHost="127.0.0.1"valCassandraHost="127.0.0.1"//:valconf=newSparkConf(true).set("spark.cassandra.connection.host",CassandraHost).set("spark.cleaner.ttl","3600").setMaster("local[12]").setAppName("CassandraTestApp")//ConnecttotheSparkcluster:lazyvalsc=newSparkContext(conf)//预处理脚本,连接的时候就执行这些CassandraConnector(conf).withSessionDo{session=>session.execute("={'class':'SimpleStrategy','replication_factor':1}")session.execute("CREATETABLEIFNOTEXISTStest.key_value(keyINTPRIMARYKEY,valueVARCHAR)")session.execute("TRUNCATEtest.key_value")session.execute("INSERTINTOtest.key_value(key,value)VALUES(1,'firstrow')")session.execute("INSERTINTOtest.key_value(key,value)VALUES(2,'secondrow')")session.execute("INSERTINTOtest.key_value(key,value)VALUES(3,'thirdrow')")}//加载connectorimportcom.datastax.spark.connector._//Readtabletest.kvandprintitscontents:valrdd=sc.cassandraTable("test","key_value").select("key","value")rdd.collect().foreach(row=>println(s"ExistingData:$row"))//Writetwonewrowstothetest.kvtable:valcol=sc.parallelize(Seq((4,"fourthrow"),(5,"fifthrow")))col.saveToCassandra("test","key_value",SomeColumns("key","value"))//.kvtable:assert(col.collect().length==2)col.collect().foreach(row=>println(s"NewData:$row"))println(s"Workcompleted,stoppingtheSparkcontext.")sc.stop()}}2.目录结构由于构建工具是用sbt,所以目录结构也必须遵循sbt规范,主要是build.sbt和src目录,其它目录会自动生成。qpzhang@qpzhangdeMac-mini:~/scala_code/CassandraTest$lltotal8drwxr-xr-x6qpzhangstaff204112612:14./drwxr-xr-x10qpzhangstaff340112517:30../-rw-r--r--1qpzhangstaff460112610:11build.sbtdrwxr-xr-x3qpzhangstaff102112517:42project/drwxr-xr-x3qpzhangstaff102112517:32src/drwxr-xr-x6qpzhangstaff204112517:55target/qpzhang@qpzhangdeMac-mini:~/scala_code/CassandraTest$treesrc/src/└──main└──scala└──CassandraTest.scalaqpzhang@qpzhangdeMac-mini:~/scala_code/CassandraTest$catbuild.sbtname:="CassandraTest"version:="1.0"scalaVersion:="2.10.4"libraryDependencies+="org.apache.spark"%%"spark-core"%"1.5.2"%"provided"libraryDependencies+="com.datastax.spark"%%"spark-cassandra-connector"%"1.5.0-M2":={casePathList(ps@_*)ifps.lastendsWith".properties"=>MergeStrategy.firstcasex=>valoldStrategy=().valueoldStrategy(x)}这里需要注意的是,sbt安装的是当时最新版本0.13,并且安装了assembly插件(这里要吐槽一下sbt,下载一坨坨的jar包,最好有FQ代理,否则下载等待时间很长)。qpzhang@qpzhangdeMac-mini:~/scala_code/CassandraTest$cat~/.sbt/0.13/plugins/plugins.sbtaddSbtPlugin("com.typesafe.sbteclipse"%"sbteclipse-plugin"%"2.5.0")addSbtPlugin("com.eed3si9n"%"sbt-assembly"%"0.14.1")3.sbt编译打包在build.sbt目录下,使用sbt命令启动。然后使用compile命令进行编译,使用assembly进行打包。在次期间,遇到了sbt-assembly-deplicate-error的问题,参考这里。>compile[success]Totaltime:0s,completed2015-11-2610:11:50>>assembly[info]Includingfromcache:slf4j-api-1.7.5.jar[info]Includingfromcache:metrics-core-3.0.2.jar[info]Includingfromcache:netty-codec-4.0.27.Final.jar[info]Includingfromcache:netty-handler-4.0.27.Final.jar[info]Includingfromcache:netty-common-4.0.27.Final.jar[info]Includingfromcache:joda-time-2.3.jar[info]Includingfromcache:netty-buffer-4.0.27.Final.jar[info]Includingfromcache:commons-lang3-3.3.2.jar[info]Includingfromcache:jsr166e-1.1.0.jar[info]Includingfromcache:cassandra-clientutil-2.1.5.jar[info]Includingfromcache:joda-convert-1.2.jar[info]Includingfromcache:netty-transport-4.0.27.Final.jar[info]Includingfromcache:guava-16.0.1.jar[info]Includingfromcache:spark-cassandra-connector_2.10-1.5.0-M2.jar[info]Includingfromcache:cassandra-driver-core-2.2.0-rc3.jar[info]Includingfromcache:scala-reflect-2.10.5.jar[info]Includingfromcache:scala-library-2.10.5.jar[info]Checkingevery*.class/*.jarfile'sSHA-1.[info]Mergingfiles[warn]Merging'META-INF/INDEX.LIST'withstrategy'discard'[warn]Merging'META-INF/MANIFEST.MF'withstrategy'discard'[warn]Merging'META-INF/io.netty.versions.properties'withstrategy'first'[warn]Merging'META-INF/maven/com.codahale.metrics/metrics-core/pom.xml'withstrategy'discard'[warn]Merging'META-INF/maven/com.datastax.cassandra/cassandra-driver-core/pom.xml'withstrategy'discard'[warn]Merging'META-INF/maven/com.google.guava/guava/pom.xml'withstrategy'discard'[warn]Merging'META-INF/maven/com.twitter/jsr166e/pom.xml'withstrategy'discard'[warn]Merging'META-INF/maven/io.netty/netty-buffer/pom.xml'withstrategy'discard'[warn]Merging'META-INF/maven/io.netty/netty-codec/pom.xml'withstrategy'discard'[warn]Merging'META-INF/maven/io.netty/netty-common/pom.xml'withstrategy'discard'[warn]Merging'META-INF/maven/io.netty/netty-handler/pom.xml'withstrategy'discard'[warn]Merging'META-INF/maven/io.netty/netty-transport/pom.xml'withstrategy'discard'[warn]Merging'META-INF/maven/joda-time/joda-time/pom.xml'withstrategy'discard'[warn]Merging'META-INF/maven/org.apache.commons/commons-lang3/pom.xml'withstrategy'discard'[warn]Merging'META-INF/maven/org.joda/joda-convert/pom.xml'withstrategy'discard'[warn]Merging'META-INF/maven/org.slf4j/slf4j-api/pom.xml'withstrategy'discard'[warn]Strategy'discard'wasappliedto15files[warn]Strategy'first'wasappliedtoafile[info]SHA-1:[info]Packaging/Users/qpzhang/scala_code/CassandraTest/target/scala-2.10/CassandraTest-assembly-1.0.jar[info]Donepackaging.[success]Totaltime:19s,completed2015-11-2610:12:224.提交到spark,执行结果qpzhang@qpzhangdeMac-mini:~/project/spark-1.5.2-bin-hadoop2.6$./bin/spark-submit--class"CassandraTestApp"--masterlocal[4]~/scala_code/CassandraTest/target/scala-2.10/CassandraTest-assembly-1.0.jar//5/11/2611:40:23INFOTaskSetManager:Startingtask0.0instage0.0(TID0,localhost,NODE_LOCAL,26660bytes)15/11/2611:40:23INFOExecutor:Runningtask0.0instage0.0(TID0)15/11/2611:40:23INFOExecutor:Fetchinghttp://10.60.215.42:57683/jars/CassandraTest-assembly-1.0./11/2611:40:23INFOCassandraConnector::TestCluster15/11/2611:40:23INFOUtils:Fetchinghttp://10.60.215.42:57683/jars/CassandraTest-assembly-1.0.jarto/private/var/folders/2l//T/spark-4030cadf-8489-4540-976e-e98eedf50412/userFiles-63085bda-aa04-4906-9621-c1cedd98c163/.tmp15/11/2611:40:23INFOExecutor:Addingfile:/private/var/folders/2l//T/spark-4030cadf-8489-4540-976e-e98eedf50412/userFiles-63085bda-aa04-4906-9621-c1cedd98c163/CassandraTest-assembly-1.0.jartoclassloader15/11/2611:40:24INFOCluster:NewCassandrahostlocalhost/127.0.0.1:9042added15/11/2611:40:24INFOCassandraConnector:ConnectedtoCassandracluster:TestCluster15/11/2611:40:25INFOExecutor:Finishedtask0.0instage0.0(TID0).2676bytesresultsenttodriver15/11/2611:40:25INFOTaskSetManager:Finishedtask0.0instage0.0(TID0)in2462msonlocalhost(1/1)15/11/2611:40:25INFOTaskSchelerImpl:RemovedTaskSet0.0,whosetaskshaveallcompleted,frompool15/11/2611:40:25INFODAGScheler:ResultStage0(collectatCassandraTest.scala:32)finishedin2.481s15/11/2611:40:25INFODAGScheler:Job0finished:collectatCassandraTest.scala:32,took2.940601sExistingData:CassandraRow{key:1,value:firstrow}ExistingData:CassandraRow{key:2,value:secondrow}ExistingData:CassandraRow{key:3,value:thirdrow}//..5/11/2611:40:27INFOTaskSchelerImpl:RemovedTaskSet3.0,whosetaskshaveallcompleted,frompool15/11/2611:40:27INFODAGScheler:ResultStage3(collectatCassandraTest.scala:41)finishedin0.032s15/11/2611:40:27INFODAGScheler:Job3finished:collectatCassandraTest.scala:41,took0.046502sNewData:(4,fourthrow)NewData:(5,fifthrow)Workcompleted,stoppingtheSparkcontext.cassandra中的数据cqlsh:test>select*fromkey_value;key|value-----+------------5|fifthrow1|firstrow2|secondrow4|fourthrow3|thirdrow(5rows)到此位置,还算顺利,除了assembly重复文件的问题,都还算ok。
‘肆’ 很简单的java 接口编译问题,求帮助!
是不是因为接口只是声明了一个东西但是没有具体实现它的方法。
然后编译了接口,但是你再接着编译另外一个类文件的时候接口的class文件的生命周期到了被自动销毁?
如果不用编译接口 直接编译你的LoginAction文件试试行不行?
‘伍’ JAVA接口和反射方面的问题,编译没问题,运行时报错
Class clazz=Class.forName(propName);
这一句抛异常了. . . 打印一下propName看是什么
可能是没取到属性文件的值
‘陆’ Protel/Altium Designer编译问题。只要器件上没有连接的接口编译时都会报错,怎么解决
这个没关系,一般error要看看,警告可以不用管,确保你逻辑上没有错就可以了
‘柒’ linux下用sbt编译scala需要安装哪些工具
1、下载sbt通用平台压缩包:sbt-0.13.5.tgz2、建立目录,解压文件到所建立目录 $ sudo mkdir /opt/scala/sbt$ sudo tar zxvf sbt-0.13.5.tgz -C /opt/scala/3、建立启动sbt的脚本文件/*选定一个位置,建立启动sbt的脚本文本文件,如/opt/scala/s...
‘捌’ 很简单的Java接口编译问题
建议你去看一下public ,protected,private 和不写这三个修饰关键字的作用域各是什么
‘玖’ sbt编译时怎么匹配scala版本
build.sbt中写入:
scalaVersion := "2.10.5"
就会使用对应的版本的库进行编译
‘拾’ Altium Designer 6.9 编译之后出现了很多警告,几乎每一个接口都有问题,具体进来看~
你按住Ctrl,用鼠标点住某的元件往出拉,,如果线和元件还连得我就不明白了,如果没继续连得,,说明不对,,,原因是元件和元件见没有加线,,你直接连到一起了,,应该元件和元件见连上线