spark的java和scala混合工程构建记录!
今天就跟这个赶上了,各种办法,各种百度。
一、maven手动构建
1、dos命令下,进入目录,构建一个scala模板的工程
mvn archetype:generate -DarchetypeGroupId=org.scala-tools.archetypes -DarchetypeArtifactId=scala-archetype-simple -DremoteRepositories=http://scala-tools.org/repo-releases -DgroupId=com.dyq -DartifactId=KafkaSparkRedis -Dversion=1.0-SNAPSHOT
4、新建Java的目录
结果如下所示,没有的就加上 ├── pom.xml ├── src│ ├── main│ │ ├── java│ │ │ └── com.jhh│ │ │ │ ── Main.java │ └── scala│ │ └── com│ │ │ ── jhh │ │── App.scala └── test│ ├── java│ └── scala
3、改造成eclipse工程:
进入工程目录,进入工程目录,进入工程目录,不要在上一层!
mvn eclipse:eclipse
我用以上2遍就成功了。
还有可以用:
mvn org.apache.maven.plugins:maven-eclipse-plugin:2.6:eclipse
完成后,会出现.project和.classpath2个目录,至少根目录是这样的!
4、使用eclipse导入工程
修改scala的JDK
5、添加管理Java的插件
修改pom.xml文件
修改pom.xml添加一个管理java源码的pluginbuild-helper plugin,添加位置 /project/build/plugins <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <executions> <execution> <phase>generate-sources</phase> <goals><goal>add-source</goal></goals> <configuration> <sources> <source>src/main/java</source> </sources> </configuration> </execution> </executions></plugin>
以上出现的问题就是scala版本冲突,
Description Resource Path Location Type
specs_2.10.4-1.6.5.jar of KafkaSparkRedis build path is cross-compiled with an incompatible version of Scala (2.10.4). In case this report is mistaken, this check can be disabled in the compiler preference page. KafkaSparkRedis Unknown Scala Version Problem
以及:
Description Resource Path Location Type
specs_2.8.0-1.6.5.jar of KafkaSparkRedis build path is cross-compiled with an incompatible version of Scala (2.8.0). In case this report is mistaken, this check can be disabled in the compiler preference page. KafkaSparkRedis Unknown Scala Version Problem
原因就是scala-tools是用2.8.0的scala版本编译的,而maven中央资源库里最高只有2.9版本的scala编译的,无解!