如何正确使用play2与maven,play2-maven-plugin和IDEA? [英] How to correctly use play2 with maven, play2-maven-plugin and IDEA?

查看:396
本文介绍了如何正确使用play2与maven,play2-maven-plugin和IDEA?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Maven中设置了一个play2项目,如这个例子,适用于Play 2.4根据 play2-maven-plugin 的官方文档。我正在使用IntelliJ IDEA。

I setup a play2 project with Maven like in this example, adapted to Play 2.4 as per the official documentation of the play2-maven-plugin. I am using IntelliJ IDEA.

现在我有一个简单的控制器:

Now I have a simple controller:

object FooController extends Controller {
  val foo = Action {
    Ok("foo")
  }

  val bar = Action {
    Redirect(routes.FooController.foo())
  }
}

my routes file contains:

my routes file contains:

GET /foo    controllers.FooController.foo
GET /bar    controllers.FooController.bar

现在,我遇到了几个问题。

Now, I ran into several problems.

第一个问题是 FooController 没有找到 routes 。我不得不在命令行上手动执行 mvn play2:routes-compile 来生成路由,但它们位于名为 target /的排除目录中src_managed /主。为了让它们在范围内,我必须像这样使用 build-helper-maven-plugin

The first problem was FooController not finding routes. I had to manually do mvn play2:routes-compile on the command line to have the routes generated, but they are in an excluded directory named target/src_managed/main. To get them in scope, I have to use the build-helper-maven-plugin like so:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>${build-helper-maven-plugin.version}</version>
    <executions>
        <execution>
            <phase>process-sources</phase>
            <goals><goal>add-source</goal></goals>
            <configuration>
                <sources>
                    <source>${project.build.directory}/src_managed/main</source>
                </sources>
            </configuration>
        </execution>
    </executions>
</plugin>

我做 mvn clean play2:routes-compile后路线工作再次,IDEA显示没有错误。但是,我必须避免触及托管源文件夹,并避免在那里打开任何生成的源文件,即使只是为了查看它们,因为会有其他参考问题,但实际上并不存在,但它们是因为IDEA没有计算这是一个Play2项目。在命令行上执行 mvn包play2:run 时,应用程序启动并按预期工作。

The routes work after I do mvn clean play2:routes-compile again, and IDEA shows no errors. However, I must avoid touching the managed sources folder, and avoid opening any generated source files in there, even only for looking at them, because there will be other reference problems which are really not there, but they are there because IDEA does not figure out it is a Play2 project. When doing a mvn package play2:run on the command line, the application starts and works as expected.

不幸的是,我目前必须使用Maven,因为它是一个包含许多子模块的大型Maven项目,我无法在几小时/几天内更改为SBT。

Unfortunately, I currently must use Maven because it is a big Maven project with many submodules I cannot change to SBT in a few hours/days.

那么,是否有任何建议如何正确使用它并让IDEA将我的项目识别为Play2?当我选择构建/重建项目或<$时,是否可以自动运行 play2:resources-compile 目标c $ c>制作模块?

So, is there any advice on how to correctly use this and get IDEA to recognize my project as Play2? Is it possible to auto-run the play2:resources-compile goal when I select Build/Rebuild Project or Make module?

推荐答案

使用示例项目而不是这个

我使用ScalaIDE,但我测试了Idea整合,它的工作原理。导入Maven项目,添加Scala支持,重建。

I use ScalaIDE, but I've tested Idea integration and it works. Import Maven project, add Scala support, rebuild.

这篇关于如何正确使用play2与maven,play2-maven-plugin和IDEA?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆