2018.11.02
前言
項目需求改變,需要開發Spark應用,而原項目是基於Java開發的,所以就需要原項目能支持Java/Scala混編。原項目採用的是Maven項目管理工具,編輯器是IDEA。
方法
本方法基於已存在的Maven項目,未創建Maven項目的可使用mvn archetype:generate
創建一個新項目:
- 在pom.xml中添加
scala-maven-plugin
等插件1:
<project>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.4.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
- 調整目錄結構:
src/main/java
src/main/scala
- IDEA支持Scala2, 一步步配置即可: