[Eclipse构建maven scala和java项目]

Eclipse构建maven scala项目

一、安装环境

操作系统:Windows 10

Eclipse版本:

JVM:1.8

Scala版本:2.11.0

二、插件安装

2.1 安装eclipse scala插件

eclipse marketplace中安装scala插件

 [Eclipse构建maven scala和java项目]_第1张图片

在选项卡[Search]中输入scala,安装Scala IDE 4.7.x,根据提示一次安装即可。

 [Eclipse构建maven scala和java项目]_第2张图片

 

2.2 安装m2e-scala插件

Installl New Software中安装m2e-scala插件

 [Eclipse构建maven scala和java项目]_第3张图片

安装URLhttp://alchim31.free.fr/m2e-scala/update-site/

 [Eclipse构建maven scala和java项目]_第4张图片

选择响应的插件安装即可

 

2.3 安装Maven工程模板

创建Maven工程

 [Eclipse构建maven scala和java项目]_第5张图片

新建Archetype,因为maven默认没有。

Group Id: net.alchim31.maven

Artifact Id: scala-archetype-simple

Version:1.6

点击[Add Archetype],如下图所示:

 [Eclipse构建maven scala和java项目]_第6张图片

选择刚刚添加的scala-archetype-simple这个模板就可以了。

 [Eclipse构建maven scala和java项目]_第7张图片

 

三、编译设置

Scala项目Maven项目编译打包过程中,可能会出现的一些问题。以下是本机机器上编译出现的一些问题:

3.1 问题一

[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 : or :[:]:. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-site, site, post-site, site-deploy, pre-clean, clean, post-clean. -> [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/NoGoalSpecifiedException

 

解决方法:

pom.xml文件中添加<defaultGoal>installdefaultGoal>如下图所示。

[Eclipse构建maven scala和java项目]_第8张图片 

3.2 问题二

[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,如下图所示:

 [Eclipse构建maven scala和java项目]_第9张图片

最后的编译结果成功:

 [Eclipse构建maven scala和java项目]_第10张图片

 

四、运行测试

 [Eclipse构建maven scala和java项目]_第11张图片

你可能感兴趣的:(maven,scala,maven,scala)