maven for scala

eclipse/myeclipse maven-for-scala插件 maven-for-scala插件,用来解决eclipse/myeclipse scala插件安装后报错的问题: Plugin execution not covered by lifecycle configuration: net.alchim31.maven:scala-maven-plugin:3.2.0:compile (execution: default, phase: compile) 立即下载

Introduction to maven

Maven is a builder like make or ant, written in java. It's a commande line tool, IDE (Eclipse, Netbeans, IDEA) have plugins to handle and integrate project powered by maven. It could be used to create lib (jar), webapps (ear) and any other type of "artifact". It prefers convention over configuration, and configuration over instruction. What that mean exactly ?
  • every action have a default configuration (= the convention).
  • every action is a goal defined into a plugin (aka mojo), and for common case, you will try to use existing plugin instead of calling (more) low level instruction (like copy file,...)
Before creating your first scala project, You need to know some info:

a command line tool
"mvn" is the name of the command line tool to call maven 2.x. To display help, run   mvn help 
the project descriptor : the file [prj]/pom.xml
It's the file when every project information are stored (name, version, dependencies, license, mailing-list,...)
the build lifecycle :
The build lifecycle is defined by a sequence of phases, the main are :
  • compile - compile the source code of the project
  • test - test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
  • package - take the compiled code and package it in its distributable format, such as a JAR.
  • integration-test - process and deploy the package if necessary into an environment where integration tests can be run
  • install - install the package into the local repository, for use as a dependency in other projects locally
  • deploy - done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.
A phase is depend of the previous one, so when you request the phase test, then the phase compile is done before,...
Directory layout
see below for a scala project
repository
Maven use repositories (local and remote) to store and to retrieve artifacts and their descriptor (pom). Artifacts are jar, war,... and they could be used as dependencies, maven plugin,...
By default, maven search artifact in the central repository. A "dedicated" repository for Scala stuff is available at  http://scala-tools.org/repo-releases/.

Your first scala project with maven


In the following, we will run maven for the first time. Maven download what it need to work from remote repositories, and cache the downloaded artifact into its local repository (default is   $HOME/.m2/repository). It only download what it need for the requested phases/goals (lazy downloading). So the   first runs could be very long. 

Step 0: installation


  • install jdk 1.5+ (eg : on my box $HOME/bin/soft-linux/jdk-1.5.0_03)
  • install maven 2.0.8+ (eg : on my box $HOME/bin/soft-java/apache-maven-2.0.8)
    • download it
    • unarchive it
    • add the apache-maven-2.0.8/bin directory to your PATH
    • check that maven is in the path:
      • go into any directory outside the maven installation
      • run mvn help, you should see
        usage: mvn [options] [<goal(s)>] [<phase(s)>]

        Options:
        -q,--quiet Quiet output - only show errors
        ...

Step 1: create a project


You could create a project skeleton with your favorite file system tools (following directory layout as below) or you could use archetypes. Maven Archetypes are project'skeleton that could be used to create new project.
mvn org.apache.maven.plugins:maven-archetype-plugin:1.0-alpha-7:create \
-DarchetypeGroupId=org.scala-tools.archetypes \
-DarchetypeArtifactId=scala-archetype-simple \
-DarchetypeVersion=1.1 \
-DremoteRepositories=http://scala-tools.org/repo-releases \
-DgroupId=your.proj.gid -DartifactId=your-proj-id

At the end of the process you should see something like
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Sat Jan 05 17:39:47 CET 2008
[INFO] Final Memory: 6M/63M
[INFO] ------------------------------------------------------------------------

!! Success you now have a empty project under your-proj-id directory with the following directory layout :
your-proj-id/
|-- pom.xml
`-- src
|-- main
| `-- scala
| `-- your
| `-- proj
| `-- gid
| `-- App.scala
`-- test
`-- scala
`-- your
`-- proj
`-- gid
`-- AppTest.scala

In fact, the project is not empty it contains an helloworld application (App.scala) and a JUnit test (AppTest.scala). 
In the next step, you will request phase (or goals). The results will be put under your-proj-id/target directory. The target directory is the working directory where every plugin put the result of computation. If you want to clean up, request the goal "clean"
mvn clean

Step 2: compile the project


# only compile
mvn compile

If it's the first time you use maven with scala, the build should failed with a message like
...
[ERROR] FATAL ERROR
[INFO]
------------------------------------------------------------------------
[INFO] The PluginDescriptor for the plugin Plugin [org.scala-tools:maven-scala-plugin] was not found.
[INFO]
...


Cause :
the pom.xml (autogenerated) doesn't specify wish version to use for maven-scala-plugin, so maven try to use the latest available localy, and none was previously downloaded.
Solutions :
  • edit the pom.xml and define a version for the plugin
  • request to download the latest available on remote repositories

I prefer the second solution (in this case):
# only compile
mvn -U compile

now you should see
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
...

Step 3: compile and running test


The skeleton create a JUnit test AppTest.scala as sample, try to compile and run it
# compile + compile test + run test
mvn test

you should get :
...
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running your.proj.gid.AppTest
Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.054 sec <<< FAILURE!

Results :

Failed tests:
testKO(your.proj.gid.AppTest)

Tests run: 2, Failures: 1, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] There are test failures.

Please refer to /home/dwayne/tmp/your-proj-id/target/surefire-reports for the individual test results.

BUILD FAILURE, it's not good! So read the log on console :
  • there is 2 tests and one of them failed
  • the failed test is the method testKO from the class your.proj.gid.AppTest
  • see the content of the directory .../your-proj-id/target/surefire-reports for details

So you could read the problem in .../your-proj-id/target/surefire-reports/your.proj.gid.AppTest.txt
...
testKO(your.proj.gid.AppTest) Time elapsed: 0.01 sec <<< FAILURE!
junit.framework.AssertionFailedError
at junit.framework.Assert.fail(Assert.java:47)
at junit.framework.Assert.assertTrue(Assert.java:20)
at junit.framework.Assert.assertTrue(Assert.java:27)
at your.proj.gid.AppTest.testKO(AppTest.scala:26)
at your.proj.gid.AppTest.testKO(AppTest.scala:26)
...

So edit the test and fix it (it's easy), and rerun test until it pass.
Why the empty project is created with a failed test? to check that test are running and are used.

Step 4: generate the jar


# compile + run test + generate the jar
mvn package

If you fixed the test in Step 3, then a jar should be generated under the target directory. The jar doesn't contains the test classes, only the classes from src/main/scala/...

Step 5: start coding


  • add scala file under src/main/scala/... or src/test/scala/...
  • run the phases or goal you wish,...
  • if you need more lib (dependencies), edit the pom.xml and add <dependecy> node. By default you could declare dependency available on central repo (I suggest to use mvnrepository as a search engine in central repo), or in http://scala-tools.org/repo-releases/ (browse the directory, no search engine available :()

Conclusion


I expect this overlook and quick tutorial could help you to start playing with maven and scala. I plan to write other articles about "maven for scala" (about, the pom.xml and repositories). If you want to know more about maven and don't want to wai futur article, I suggest you browse the  documentation of maven. I also suggest you to take a look at the  maven-scala-plugin 2.x documentation, you'll see how to generate scaladoc, choose the scala version, or run a scala console with the project dependencies.

zz:   http://www.scala-blogs.org/2008/01/maven-for-scala.html
浅谈IC测试向量(pattern)及其转换 随着集成电路的飞速发展,其规模越来越大,对电路的质量与可靠性要求进一步提高,集成电路的测试方法也变得越来越困难,为了实现芯片的快速测试和筛选,ATE设备为其提供了强有力的支撑。ATE运用芯片设计仿真文件,将其作为芯片输入激励,通过ATE测试平台提供芯片测试环境,将芯片的输出和测试结果进行比较,以此来判定芯片的好坏。 说起IC测试,不得不说一下Pattern这个词,它中文的意思是模式。在图像处理中,这个词意思为图像的纹理特征,而在IC也即芯片测试行业,这个词实际上代表了需要测试芯片的时序特征。简单的说,在测 阅读详情

相关推荐

避坑指南:用Adams做滚珠丝杠仿真时90%人会遇到的3个建模错误

本文针对使用Adams进行滚珠丝杠动力学仿真时常见的三大建模错误,提供了详细的避坑指南。重点解析了如何避免因直接导入CAD几何体导致的性能与精度问题,科学设置接触参数以提升计算效率与结果平滑度,以及通过规范的命名与组织管理模型,确保仿真过程高效可靠。

gin88的博客 572

Eclipse+maven+scala+spark环境搭建

Eclipse+maven+scala+spark环境搭建

行人事,知天命 5955

【操作系统】 Operation System 第一章:概述

B站 陈渝老师 清华大学 https://www.bilibili.com/video/av6538245?from=search&seid=436175425155932048 相关资料(源自B站下方评论区) https://www.shiyanlou.com/courses/221 配套上机实验地址 https://b23.tv/av18273642/p1 这个适合跨考和基础薄弱的 h...

iwanderu的博客 4万+

myeclipse的scala插件安装以及maven的支持

项目需要从事scala开发,之前都是用IntelliJ IDEA和scala eclipse,但是我这里目前的环境是myeclipse,刚做的一个项目也在里面,所以就干脆直接用了,下面开始介绍如何使用myeclipse集成scala和maven的相关插件。 首先安装scala插件 地址:http://download.scala-ide.org/sdk/lithium/e44/scala211/

longyangaaoo的博客 5831

基于 LSTM 的船舶轨迹预测,单步预测

基于 LSTM 的船舶轨迹预测,单步预测

fyuhao的博客 1万+

PostgreSQL 超详细安装与使用教程:从入门到实战

本文将详细介绍PostgreSQL数据库的安装配置与基础使用。首先从Windows系统安装入手,分步骤讲解17.5版本的安装流程、环境变量配置及服务启动验证。接着重点介绍了pgAdmin4图形化管理工具的安装与使用,包括界面语言设置、数据库连接、创建与管理数据库等操作,同时对比了可视化操作与SQL命令两种方式。最后梳理了PgSQL基础语法,涵盖表的创建、增删改查操作、约束管理等内容,为初学者提供了完整的PostgreSQL入门指南。文章兼顾理论知识与实际操作,既适合数据库新手学习,也可作为开发人员的快速参考

gtf212的博客 1万+

eclipse安装maven-Scala插件

eclipse maven-Scala插件 第一步安装m2eclipse-scala,安装m2eclipse-scala步骤和安装Scala IDE类似,具体URL为http://alchim31.free.fr/m2e-scala/update-site/ Paste_Image.png 第二步:添加远程的原型或模板目录 Paste_Image.png 第三步:新建Archetype

Fly to sky 4239

GBASE南大通用GBase 8s数据库-从零开始的手动安装与实例配置指南

本文详细介绍了GBASE南大通用GBase 8s数据库的手动安装与实例配置全过程,包括环境准备、用户创建、安装包准备、实例创建、环境变量配置等关键步骤。通过实战经验分享和常见问题解决方案,帮助用户快速掌握GBase 8s数据库的安装与配置技巧,确保数据库稳定运行。

weixin_29209825的博客 454

scala java混合_三、使用maven创建scala工程(scala和java混一起)

本文先叙述如何配置eclipse中maven+scala的开发环境,之后,叙述如何实现spark的本地运行。最后,成功运行scala编写的spark程序。刚开始我的eclipse+maven环境是配置好的。系统:win7eclipse版本:Luna Release(4.4.0)maven是从EclipseMarket中安装的,如图1。当初构建eclipse+maven环境时,仅仅安装了第一个。这里...

weixin_42134054的博客 1097

顶刊《会计研究》数据复现|最新上市公司数智化数据

本文基于Python文本分析方法构建了中国A股上市公司数智化指标(1991-2024),通过识别年报中的"机器学习""智能医疗"等关键词,量化企业数字化与智能化融合程度。研究发现数智化企业更倾向于非正式渠道的定性披露以规避风险,该指标为监管完善信披规则提供了参考。研究还揭示了数智化对企业信息披露策略的转变,并提出了未来研究方向,包括数智化对绿色创新、ESG表现等影响机制。数据覆盖非金融类上市公司,采用文本挖掘技术构建结构化指标,为相关领域研究提供了微观基础。

PPdata_Academy的博客 1487

YOLO车辆测距、车辆识别与单目测距

YOLO(You Only Look Once)是一种实时物体检测系统,能够识别视频或图像中的多个对象,并确定其位置。结合车辆识别与单目测距技术,YOLO可以用于交通监控、自动驾驶等应用场景,通过单个摄像头实现车辆的识别与距离测量。YOLO结合单目测距技术,在多个应用领域展现出巨大的潜力与灵活性。其实时性和准确性为智能交通、自动驾驶等领域提供了强有力的技术支持。

走向CTO的路上... 1672

maven构建scala工程并最终运行的所有细节(scala maven helloworld)

琢磨了很久,网上虽然各种例子,但是好多都是依赖IDE的,要么就是生成jar文件后没有主清单目录,写这篇博客一次性全部解决掉。 1,文件目录 (python2.7) appleyuchi@ubuntu:~/Desktop/test3/scala-module-dependency-sample/maven-sample$ ls pom.xml  src . ├── pom.xml ├── s...

微电子学与固体电子学-俞驰 2988

IEC 104电力规约详细解读(五) - 遥控

主站下发遥控选择命令,子站进行遥控选择返校,若成功则回答遥控选择成功报文,若失败则回答失败报文。主站下发取消遥控命令或者遥控执行命令行。子站皆以报文的镜像确认。遥控命令用来实现对一个可操作设备状态的改变。在配电自动化中,包括单点命令和双点命令。通常,单点命令用于控制单点信息对象;双点命令用于控制双点信息对象。

张二狗的博客 7349

Scala IDEA for Eclipse里用maven来创建scala和java项目代码环境(图文详解)

  这篇博客   是在Scala IDEA for Eclipse里手动创建scala代码编写环境。 Scala IDE for Eclipse的下载、安装和WordCount的初步使用(本地模式和集群模式)   本博文,教大家,用maven来创建。   第一步:安装scala插件   因为,我win7下的scala环境是2.10.4 ...

weixin_30438813的博客 168

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

Changing the scala version for scala-maven-plugin

Since version 2.7 of the plugin, the scala version to use is detected from dependency to scala-library. So it suggested to not use scalaVersion configuration. But if you want to define explicitly th

DViewer的专栏 1663

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

使用Eclipse编写Spark应用程序(Scala+Maven) scala ide for eclipse

对Scala代码进行打包编译时,可以采用Maven,也可以采用sbt,相对而言,业界更多使用sbt。本教程介绍如何在 Ubuntu中使用 Eclipse 来开发 scala 程序(使用Maven工具),在Spark 2.1.0,scala 2.11.8 下验证通过。使用 Eclipse,我们可以直接运行代码,省去许多繁琐的命令。(相关文章:如何在 Ubuntu中使用 Eclipse 来开发 sca...

kwame211的博客 1319

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

【scala】idea 刷新maven或gradle报错 Cannot find project Scala library 2.11.12 for module

向configuration标签添加scala版本信息。

lisacumt的专栏 1253

jdk, scala, maven, gradle, ant install shell bash, and Dockerfile for Ubuntu:14:04

Shell: The jdk tar and version must be jdk-7u79-linux-x64.tar.gz #!/bin/bash sudo tar -zxvf jdk-7u79-linux-x64.tar.gz -C /usr/local echo "#set java environment" >> /etc/profile; echo "export

刘伟臣的笔记本 452

spark需要maven管理吗_使用Eclipse编写Spark应用程序(Scala+Maven)

点击这里观看厦门大学林子雨老师主讲《大数据技术原理与应用》授课视频【版权声明】博客内容由厦门大学数据库实验室拥有版权,未经允许,请勿转载![返回Spark教程首页]对Scala代码进行打包编译时,可以采用Maven,也可以采用sbt,相对而言,业界更多使用sbt。本教程介绍如何在 Ubuntu中使用 Eclipse 来开发 scala 程序(使用Maven工具),在Spark 2.1.0,scal...

weixin_36334262的博客 261

Jackson Module for Scala 安装与使用指南

```plaintext jackson-module-scala │ ├── CHANGELOG.md - 版本更新日志 ├── LICENSE - 许可证文件 ├── README.md - 项目简介和快速入门 ├── build.gradle - Gradle构建脚本 ├── project

gitblog_00721的博客 760

Cannot find project Scala library 2.12 for module

## 问题场景 构建项目时报错 Cannot find project Scala library 2.12 for module xxxx ## 解决方案 在File -> Project Structure中查看对应module的Dependencies,检查依赖包版本是否正确,去掉重复多余的scala依赖包(一般都是因为替换scala版本时,没有自动清除之前的scala依赖包导致的,这还可能会导致运行时异常java.lang.NoSuchMethodError)

m0_56602092的博客 9252

scala eclipse maven开发环境搭建

    对于scala 开发,很多人都选择sbt进行构建,但是笔者一直使用maven进行构建,比较熟悉,因此搭建了一套scala + eclipse + maven的开发环境,下面简单记录下搭建过程   1. 下载一个Scala IDE for Eclipse,地址:http://scala-ide.org/,下载完成之后进行安装,与正常的eclipse安装差不多   2. 安装mav...

醉意再现 393

scala 简单总结

语法对比速记 1.scala的数组与java相比是可变的数据结构。 2.for(i

闪烁的星空 215

Scala IDE for Eclipse的下载、安装和WordCount的初步使用(本地模式和集群模式)

      不多说,直接上干货!        这篇博客是,    是在Scala IDEA for Eclipse里maven创建scala和java代码编写环境。 Scala IDEA for Eclipse里用maven来创建scala和java项目代码环境(图文详解)             本博文包括:    Scala IDE for Eclipse的下载...

weixin_33994429的博客 313

用maven来创建scala和java项目代码环境(图文详解)(Intellij IDEA(Ultimate版本)、Intellij IDEA(Community版本)和Scala IDEA for ...

  不多说,直接上干货! 为什么要写这篇博客?   首先,对于spark项目,强烈建议搭建,用Intellij IDEA(Ultimate版本),如果你还有另所爱好尝试Scala IDEA for Eclipse,有时间自己去玩玩。但最好追随大流。   对于hadoop项目,强烈建议用eclipse。   其次,出于有博友给我留言的索求需要,为了更高效率和高质...

weixin_30764137的博客 69

Scala学习(一)

文章目录win10安装IDEA使用基础数据类型类型转换运算符循环异常处理 win10安装 先下载sdk包 :https://www.scala-lang.org/download/2.10.4.html 解压安装 配置环境变量(SCALA_HOME)和java的一样 --》 %SCALA_HOME%\bin 在cmd里输入scala测试 IDEA使用 下载scala插件 安装之后重启idea 新建一个maven项目 右键点击项目名 --》选择 Add Frameworks Support —

haobo__的博客 136
上一篇: What does => and () => mean in Scala
下一篇: Map, Map and flatMap in Scala
DViewer
博客等级 码龄16年 16粉丝 6原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值