在Mac OSX上运行IntelliJ中的第一个playframework示例

Dav*_*lla 10 scala intellij-idea playframework

在我的新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
Run Code Online (Sandbox Code Playgroud)

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

> 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
Run Code Online (Sandbox Code Playgroud)

并在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
Run Code Online (Sandbox Code Playgroud)

然后当我尝试运行单元测试时:

Project -> myapp -> test -> ApplicationSpec -> (right click) -> Run
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

scala: ?ompiler library for module bigbrother not found: Right(Project) / Right(scala-2.10.0) 
Run Code Online (Sandbox Code Playgroud)

实际上,有几个错误:

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
Run Code Online (Sandbox Code Playgroud)

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

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)”.
Run Code Online (Sandbox Code Playgroud)

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

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.
Run Code Online (Sandbox Code Playgroud)

我需要做些什么来使它工作?


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

生成IntelliJ项目

> cd myapp
> play
> idea no-sbt-build-module
Run Code Online (Sandbox Code Playgroud)

(而不仅仅是'想法')

然后,项目设置 - >库选择"Scala 2.9.2"并单击" - "将其删除.

然后,项目设置 - >模块 - > my_app - > Scala - > 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/选择确定.将其命名为"my scala 2.10.0 bundle".

然后,再次转到项目设置 - >模块 - > my_app - > Scala - > Scala编译器,现在你有两个,你刚刚创建的"我的scala 2.10.0包",标准的那个:"Scala 2.10.0 (版本2.10.0)"用黑色/灰色书写.选择标准的,然后删除您创建的全局库.

我不知道为什么会这样,我真的不想花更多的时间来发现这一点.目前,这种解决方法对我有用.但如果你发现,请随时添加评论.

Mar*_*ila 10

通过以下方式生成构思项目可以解决此问题:

$ play  # start play from command line
[your-play-project] $ idea no-sbt-build-module
Run Code Online (Sandbox Code Playgroud)

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


Ale*_*ula 8

以下是同样的错误帮助我的原因:

  1. 删除任何Scala 2.9.2依赖项
  2. 去吧Project Structure -> Global libraries.创建一个新的,称为scala-bundle.为2.10添加scala-compiler.jar,scala-library.jar,scala-reflect.jar.
  3. 最后,转到Project Structure -> Modules -> myapp -> Scala并选择scala-bundle.

对于模块共享错误,请转到Project Structure -> Modules -> <each module> -> Paths并更改路径,使它们不相同.