IDEA 环境下Scala 和 Java 混合开发(Tips)
2019-01-25 本文已影响0人
ggr
- 正常情况下,即使安装好了Scala和IDEA scala插件,我们新建的maven项目,IDEA不会出现新建scala的选项 要想IDEA自动有这个选项还需要在Pom.xml引入build插件
<build>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.15.2</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
- 编写scala的时候不要忘了引入scala,例如
import org.apache.flink.api.scala.ExecutionEnvironment
//不引用这个下面的代码会报错No implicits found for parameter evidence$11: TypeInformation[String]
import org.apache.flink.api.scala._
/**
* @Auther: GuiRunning
* @Date: 2019/1/25 22:35
* @Description:
*/
object WordCountJava {
def main(args: Array[String]): Unit = {
val env = ExecutionEnvironment.getExecutionEnvironment
val lines = env.readTextFile("/test.txt");
val c = lines.flatMap(x=>x.split("\\W+"))
.map(x=>Tuple2(x,1)).groupBy(0).sum(1).print()
}
}