简介
java和scala混合编程时,会报找不到符号的问题。 如果你使用的是maven,可以通过配置pom.xml来解决java、scala混合编程的问题。
解决方案
需要设置properties和plugin,设置方法如下。
添加properties
在properties中加入:
<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target>
plugin
在plugins中加入:
<plugin> <groupId>net.alchim31.maven</groupId> <artifactId>scala-maven-plugin</artifactId> <version>3.2.2</version> <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>
编译
mvn scala:compile