在Play 2.0 Framework中运行对象 [英] Running Objects in Play 2.0 Framework

查看:100
本文介绍了在Play 2.0 Framework中运行对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个Scala Play 2.0项目,然后添加具有准系统main功能的Test对象.

I create a Scala Play 2.0 project then add a Test object with a barebones main function.

运行Test对象时,我得到一个ClassDefNotFoundError.这是因为Test对象显然没有被编译到任何项目文件夹中的文件中.

When I run the Test object I get a ClassDefNotFoundError. This is because the Test object is apparently not being compiled into a file in any project folder.

运行捆绑的Play服务器工作正常.

Running the bundled Play server works fine.

是否有人尝试将可运行对象添加到Scala Play框架项目中并获得成功?

Has anyone tried adding a runnable object to a Scala Play framework project and had success?

Test对象是在名为test-module的Play项目中的新模块中创建的.

The Test object is being created in a new module, within the Play project named test-module.

****更新****

**** Update ****

似乎SBT与测试模块"模块存在某种冲突. Play是一个SBT项目,因此会编译到其目标"目录.但是'test-module'不是SBT,因此希望编译到'out'目录.问题在于,编译后的文件永远不会进入"out"目录,实际上它们根本不会进入任何目录.

It seems like SBT is somehow conflicting with the 'test-module' module. Play is an SBT project so it compiles to its 'target' directory. However 'test-module' is not SBT and therefore wants to compile to the 'out' directory. Problem is the compiled files never make it to the 'out' directory, in fact they don't make it to any directory at all.

推荐答案

IntelliJ的Play项目模板假定Play将是顶级目录.

IntelliJ's template for a Play project assumes Play will be the top level directory.

在此处创建模块时,必须自动将其注册到SBT中.

When creating a module inside here, one must register it with SBT as it is not done automagically.

并确保对源文件遵循module-> src-> main-> scala约定,或在build.sbt中进行更改

And make sure to follow the module->src->main->scala convention for source files, or change it in the build.sbt

这篇关于在Play 2.0 Framework中运行对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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