加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – 在Mac OSX上运行IntelliJ中第一个playframework的例子

发布时间:2020-12-16 19:08:29 所属栏目:安全 来源:网络整理
导读:在我的新Mac OSX 10.8.3中, 我安装 scala 2.10.0,播放2.1.0和IntelliJ12, 并创建一个播放项目如下: #install brew ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)" brew --version0.9.4# update brew database cd $(brew --prefix) brew
在我的新Mac OSX 10.8.3中,
我安装 scala 2.10.0,播放2.1.0和IntelliJ12,
并创建一个播放项目如下:

#install brew
> ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
> brew --version
0.9.4

# update brew database
> cd $(brew --prefix)
> brew update
> cd $(brew --prefix) && git pull --rebase

# get scala 2.10.0
> brew versions scala
2.10.1   git checkout 79dc6f1 Library/Formula/scala.rb
2.10.0   git checkout 8ca07aa Library/Formula/scala.rb
2.9.2    git checkout 8896425 Library/Formula/scala.rb
...

> git checkout 8ca07aa Library/Formula/scala.rb   # 2.10.0
> brew install scala
> scala -version
Scala code runner version 2.10.0 -- Copyright 2002-2012,LAMP/EPFL


# install play 2.1.0
> brew versions play
2.1.0    git checkout 6a70797 Library/Formula/play.rb
...

> brew install play
> play -version
play! 2.1.0 (using Java 1.6.0_43 and Scala 2.10.0),http://www.playframework.org

我创建一个播放应用程序:

> cd ~/
> play new myapp
name: myapp
Create a simple Scala application

# generate IntelliJ project:
> cd myapp
> play
> idea
[info] Created /Users/david/myapp/.idea_modules/myapp.iml
[info] Created /Users/david/myapp/.idea_modules/myapp-build.iml

并在IntelliJ中打开该项目:

# Install IntelliJ 12 Ultimate Edition
Download it from http://www.jetbrains.com/idea/
12.0.4,Build #IU-123.169
Build on February 13,2013

# install scala plugin in IntelliJ
run IntelliJ,Preferences -> plugins -> Browse from repositories -> add scala.
current version: 0.7.134

# open myapp project in IntelliJ
File -> Open Project,chose the directory /Users/david/myapp

那么当我尝试运行单元测试时:

Project -> myapp -> test -> ApplicationSpec -> (right click) -> Run

我得到这个错误:

scala: Сompiler library for module bigbrother not found: Right(Project) / Right(scala-2.10.0)

其实有几个错误:

in File -> Project Structure -> Modules,there are two modules:
-myapp
-mypp-build

File -> Project Structure -> Modules -> myapp -> Scala
   Compiler library: scala-2.10.0 [not found]
   <<< ERROR

File -> Project Structure -> Modules -> myapp-build -> Dependencies:
   scala-2.9.2
   <<< ERROR

如果我纠正第一个错误如下,

File -> Project Structure -> Modules -> myapp -> Scala -> Compiler library
and from the dropdown list I select the second valid option “scala-2.10.0 (version 2.10.0)”.

然后,重新运行测试,会产生错误:

scala: Output path /Users/david/bigbrother/project/target/scala_2.9.2 is shared between: Module 'bigbrother-build' production,Module 'bigbrother-build' tests
Currently external Scala compiler prohibits output path sharing.
Either disable the external build mode or configure separate output paths.
TIP: you can use Project Artifacts to combine compiled classes.

我需要做什么才能使其工作?

更新:基于Marius和alexwriteshere的答案的解决方案

生成IntelliJ项目

> cd myapp
> play
> idea no-sbt-build-module

(而不是“想法”)

然后,
项目设置 – >图书馆
选择“Scala 2.9.2”,然后单击“ – ”将其删除.

然后,
项目设置 – >模块 – > my_app – > Scala – >斯卡拉编译
在这个下拉列表中,选择了用Scala 2.10.0写的红色.
移动到列表的顶部,并选择以黑色/灰色编写的“Scala 2.10.0(版本2.10.0)”.

注意

有时(我不知道为什么)选择“Scala 2.10.0(版本2.10.0)”用黑色/灰色写入下拉列表中不可用.
一个适用于我的解决方法,使其可用如下:
项目设置 – >全球图书馆 – > – > Java的
从这个目录中选择这些文件scala-compiler.jar,scala-library.jar和scala-reflect.jar:/usr/local/Cellar/scala/2.10.0/libexec/lib/
选择确定.
给它名称“我的scala 2.10.0捆绑”.

然后再转到项目设置 – >模块 – > my_app – > Scala – >斯卡拉编译
现在你有两个,你刚刚创建了“我的scala 2.10.0捆绑”,标准的一个:“Scala 2.10.0(版本2.10.0)”用黑色/灰色写.选择标准的,并删除您创建的全局库.

我不知道为什么会发生这种情况,我真的不想花更多的时间找到这个.目前这种解决方法对我来说是有效的.但如果您发现,请随时添加评论.

解决方法

这个问题可以通过生成想法项目来解决:

$play  # start play from command line
[your-play-project] $idea no-sbt-build-module

这将使IntelliJ针对Scala的默认构建机制,这不会导致这些问题.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读