本文介绍了如何在Play Framework和Scala中使用IntelliJ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在尝试将IntelliJ与play framework 2.11应用程序一起使用。

I am trying to use IntelliJ with a play framework 2.11 application.

我安装了Play Framework 2插件和IntelliJ的Scala插件。

I installed the Play Framework 2 plugin and the Scala plugin for IntelliJ.

我创建了一个Play应用程序。我一直在努力在IntelliJ中编写和运行Specs 2测试。我的运行配置说在运行Specs 2测试时首先运行make,但是看起来我的测试类看起来不像。继续告诉我它找不到规范。当我查看文件系统时,目标/测试类中没有代码,目录为空。此外,至少与运行Play控制台相比,似乎需要花费很长时间才能进行构建。

I created a Play application. I have been struggling writing and running Specs 2 tests in IntelliJ. My run config says to run "make" first when running the Specs 2 test, however it doesn't look like my test classes are being generated. Keeps on telling me that it could not find the specification. When I look on the file system, there is no code in target/test-classes, the directory is empty. Further, it seems to take a LONG time to do the build, at least compared to running the Play console.

我想看看人们如何使用Play with IntelliJ。您是否只使用IntelliJ作为编辑器,并通过Play控制台运行所有内容?

I wanted to see how people are using Play with IntelliJ. Do you just use IntelliJ as an editor, and run everything through the Play console?

有没有办法可以在IntelliJ中运行应用程序测试(获取测试类运行)?

Is there a way whereby you can run your Application tests in IntelliJ (getting your test classes to run)?

我在运行Play控制台并运行~test-only test = xxx.Spec时从未遇到任何问题。它通常非常快。

I have never had any problem running the Play console and running ~test-only test=xxx.Spec. It has typically been rather fast.

当我尝试运行我的Specs2测试时,这是我在IntelliJ中获得的异常:

Here is the exception I am getting in IntelliJ when I try to run my Specs2 tests:

Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.jetbrains.plugins.scala.testingSupport.specs2.JavaSpecs2Runner.runSingleTest(JavaSpecs2Runner.java:130)
    at org.jetbrains.plugins.scala.testingSupport.specs2.JavaSpecs2Runner.main(JavaSpecs2Runner.java:76)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.RuntimeException: can not create specification: test.ApplicationSpec
    at scala.sys.package$.error(package.scala:27)
    at org.specs2.specification.SpecificationStructure$.createSpecification(BaseSpecification.scala:96)
    at org.specs2.runner.ClassRunner.createSpecification(ClassRunner.scala:64)
    at org.specs2.runner.ClassRunner.start(ClassRunner.scala:35)
    at org.specs2.runner.ClassRunner.main(ClassRunner.scala:28)
    at org.specs2.runner.NotifierRunner.main(NotifierRunner.scala:24)
    ... 11 more


推荐答案

更新:在IntelliJ IDEA的较新版本中,不再需要从播放/激活器创建模块。 IntelliJ IDEA现在为SBT项目提供了非常好的支持。如果存在,删除项目中的所有与想法相关的目录。然后在IntelliJ IDEA中单击文件 - >打开并选择build.sbt文件。这就是全部。

Update: In newer versions if IntelliJ IDEA, it is no longer necessary to create the module from play/activator. IntelliJ IDEA has now a really good support for SBT projects. If exists, delete all the idea related directories inside your project. Then in IntelliJ IDEA click File -> Open and choose your build.sbt file. That's all.

IntelliJ IDEA与Play Framework 2有很好的集成。有时它会卡住,但大多数时候它运行。我用它来运行(单个,全部)测试,启动或调试播放应用程序并编辑我的代码(o;这一切都来自IDE内部,没有sbt控制台。

IntelliJ IDEA has a good integration for the Play Framework 2. Sometimes it jams, but most of the time it runs. I use it to run(single, all) tests, start or debug the play application and edit my code (o; And this all from within the IDE and without the sbt console.

这是一个包含最重要步骤的简短教程。目前我使用IntelliJ IDEA 12.1和最新的Play Framework 2和Scala插件。

Here is a short tutorial with the most important steps. Currently I use IntelliJ IDEA 12.1 with the newest Play Framework 2 and Scala plugins.

1。创建新应用程序

play new myapp

2.创建IDE模块

启动播放控制台:

cd newapp
play

创建模块:

idea with-sources=yes
exit

3.配置IDE


  1. 打开新创建的项目

  2. 打开模块设置(选择项目并按F4)

  3. 添加Scala库到你的项目
  1. Open the newly created project
  2. Open the module settings(select project and press F4)
  3. Add the Scala library to your project

  1. 选择 Modules-> myapp-> Depe ndencies

  2. 按加号图标并选择库(2)

  3. 添加Scala 2.10.0项目库


  • 选择Scala Facet中的编译器库

  • Select the Compiler Library in the Scala Facet


    1. 选择 Facets-> Scala(myapp) )

    2. 编译器库设置为Scala 2.10.0

    1. Select Facets->Scala(myapp)
    2. Set the Compiler library to Scala 2.10.0


  • 修正错误

  • Fix the errors


    1. 选择 Modules-> myapp-build-> Dependencies-> scala-2.9.2 然后按减号icon

    2. 选择 Libraries-> Scala 2.9.2 并按减号图标

    1. Select Modules->myapp-build->Dependencies->scala-2.9.2 and press the minus icon
    2. Select Libraries->Scala 2.9.2 and press the minus icon


  • 修复 myapp-build 模块的输出路径

  • Fix the output Path for the myapp-build module


    1. 选择 Modules-> myapp-build-> Paths

    2. 附加到输出路径(X:\ project] \ myapp \ project \ target \\ scala_2.9.2 \classes)

    3. 测试类附加到测试输出路径(X:\ project] \ myapp\project\target\scala_2.9.2\测试课程)

    1. Select Modules->myapp-build->Paths
    2. Append classes to the Output path(X:\projects\myapp\project\target\scala_2.9.2\classes)
    3. Append test-classes to the Test output path(X:\projects\myapp\project\target\scala_2.9.2\test-classes)


  • 4。运行测试

    选择测试目录下的 ApplicationSpec ,然后单击运行'ApplicationSpec'上下文菜单。您应该收到无法找到编译模板的错误。这是因为IDE不编译模板,但这可以通过运行一次应用程序来完成。也请按照第5点,然后再次运行测试。

    Select the ApplicationSpec under the test directory and click Run 'ApplicationSpec' from the context menu. You should get an error that the compiled template could not be found. This is because the IDE doesn't compile the templates, but this can be done by run the application once. Also follow point 5 and then run the test again.

    5。运行应用程序

    选择一个控制器,然后从上下文菜单中单击运行Play 2 App 。这应该在地址上启动应用程序: http:// localhost:9000 /

    Select a controller and click Run Play 2 App from context menu. This should start the application on address: http://localhost:9000/.

    6。更新依赖项

    如果更新应用程序依赖项,则必须告知IDE有关此更改的信息。此外,在运行 play update 命令后,您必须关闭IDE并从项目目录中删除一些文件。如果在删除文件之前执行播放想法命令,则会在播放项目中获得双重依赖。

    If you update your application dependencies then you must tell the IDE about this changes. Also after running the play update command you must close the IDE and remove some files from project directory. If you execute the play idea command before removing the files, you get double dependencies in your play project.

    执行以下步骤更新您的依赖项:

    Execute the following steps to update your dependencies:


    1. 从您的游戏中运行更新任务控制台

    2. 删除 .idea_modules .idea / libraries 目录

    3. 在播放控制台中使用-source = yes 命令运行构思

    4. 再次运行第3步

    1. Run the update task from your play console
    2. Remove the .idea_modules and .idea/libraries directories
    3. Run the idea with-sources=yes command in the play console
    4. Run step 3 again

    这篇关于如何在Play Framework和Scala中使用IntelliJ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    1403页,肝出来的..

    09-06 22:18