操作系统:Windows 10
Eclipse版本:
JVM:1.8
Scala版本:2.11.0
从eclipse marketplace中安装scala插件
在选项卡[Search]中输入scala,安装Scala IDE 4.7.x,根据提示一次安装即可。
从Installl New Software中安装m2e-scala插件
安装URL:http://alchim31.free.fr/m2e-scala/update-site/
选择响应的插件安装即可
创建Maven工程
新建Archetype,因为maven默认没有。
Group Id: net.alchim31.maven
Artifact Id: scala-archetype-simple
Version:1.6
点击[Add Archetype],如下图所示:
选择刚刚添加的scala-archetype-simple这个模板就可以了。
Scala项目Maven项目编译打包过程中,可能会出现的一些问题。以下是本机机器上编译出现的一些问题:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.111s
[INFO] Finished at: Tue Apr 24 09:20:52 CST 2018
[INFO] Final Memory: 6M/184M
[INFO] ------------------------------------------------------------------------
[ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoGoalSpecifiedException
解决方法:
在pom.xml文件中添加<defaultGoal>installdefaultGoal>,如下图所示。
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building mvnscala 1.0.0-RELEASE
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mvnscala ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory G:\Study\workspace\scala\mvnscala\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ mvnscala ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- scala-maven-plugin:3.2.0:compile (default) @ mvnscala ---
[INFO] G:\Study\workspace\scala\mvnscala\src\main\scala:-1: info: compiling
[INFO] Compiling 1 source files to G:\Study\workspace\scala\mvnscala\target\classes at 1524533443969
[ERROR] scalac error: bad option: '-make:transitive'
[INFO] scalac -help gives more information
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.758s
[INFO] Finished at: Tue Apr 24 09:30:44 CST 2018
[INFO] Final Memory: 11M/232M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal net.alchim31.maven:scala-maven-plugin:3.2.0:compile (default) on project mvnscala: wrap: org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
解决方法:
根本原因是mvn clean package默认只处理java源代码的编译、打包,而对scala进行处理,所以编译时失败。
在Maven编译的窗口中添加:clean scala:compile compile package,如下图所示:
最后的编译结果成功: