Running Objects in Play 2.0 Framework

2019-08-10 14:10发布

问题:

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

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.

Running the bundled Play server works fine.

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

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

**** Update ****

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.

回答1:

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

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

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