scala play2 框架我的模板没有看到。: 包views.html 不存在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10910215/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 04:13:20  来源:igfitidea点击:

play2 framework my template is not seen. : package views.html does not exist

javamodel-view-controllertemplatesscalaplayframework

提问by Capacytron

The problem is that controller doesn't see template I want to use:

问题是控制器没有看到我想使用的模板:

[etl_admin] $ compile [info] Compiling 3 Scala sources and 4 Java sources to D:\ECLIPSE_WORKSPACES\play2_apps\etl_admin\target\scala-2.9.1\classes... [error] D:\ECLIPSE_WORKSPACES\play2_apps\etl_admin\app\controllers\EtlWorkflowSeqNodeController.java:7: error: package views.html.etlworkflowseqnode does not exist [error] import views.html.etlworkflowseqnode.list; [error]
^ [error] D:\ECLIPSE_WORKSPACES\play2_apps\etl_admin\app\controllers\EtlWorkflowSeqNodeController.java:14: error: cannot find symbol

[error] list.render(EtlWorkflowSeqNode.findTree(jobId)) [error] ^ [error] symbol: variable list [error]
location: class EtlWorkflowSeqNodeController [error] 2 errors [error] {file:/D:/ECLIPSE_WORKSPACES/play2_apps/etl_admin/}etl_admin/compile:compile: javac returned nonzero exit code [error] Total time: 7 s, completed 05.06.2012 17:14:44

[etl_admin] $ compile [info] 将 3 个 Scala 源和 4 个 Java 源编译到 D:\ECLIPSE_WORKSPACES\play2_apps\etl_admin\target\scala-2.9.1\classes... [错误] D:\ECLIPSE_WORKSPACES\play2_apps\etl_admin\ app\controllers\EtlWorkflowSeqNodeController.java:7: 错误:包views.html.etlworkflowseqnode 不存在[错误] import views.html.etlworkflowseqnode.list; [错误]
^ [错误] D:\ECLIPSE_WORKSPACES\play2_apps\etl_admin\app\controllers\EtlWorkflowSeqNodeController.java:14: 错误:找不到符号

[错误] list.render(EtlWorkflowSeqNode.findTree(jobId)) [错误] ^ [错误] 符号:变量列表[错误]
位置:类EtlWorkflowSeqNodeController [错误] 2 个错误[错误] {file:/D:/ECLIPSE_WORKSPACES/play2_apps /etl_admin/}etl_admin/compile:compile: javac 返回非零退出代码 [错误] 总时间:7 秒,完成 05.06.2012 17:14:44

Here is controller code:

这是控制器代码:

package controllers;

import play.mvc.Controller;
import play.mvc.Result;
import models.EtlWorkflowSeqNode;
import play.db.jpa.Transactional;
import views.html.etlworkflowseqnode.list; /*LINE #7, Eclipse really tells that there is no such package*/

public class EtlWorkflowSeqNodeController  extends Controller {

    @Transactional
    public static Result list(Integer jobId) {
        return ok(
            list.render(EtlWorkflowSeqNode.findTree(jobId))
        );
    }
}

I've attached an image with my project tree. There is such package and there is template named "list". My Eclipsewhat do I do Wrong

我在我的项目树中附上了一张图片。有这样的包,并且有名为“list”的模板。 我的日食我该怎么办 错

回答by Capacytron

Omg, the problem was so easy! *classes_managed* (this folder keeps compiled scala templates) were not updated with newly added templates. I did try to call play compileyesterday, it doesn't help. New templates from new package were not compiled. This morning I've called play clean compileaaand... hooray! I did get compiled templates and problem with missing package gone away (don't forget to refresh Eclipse project, force it to update exisitng project structure from file system. It likes to cache everything.)

天哪,问题太简单了!*classes_managed*(此文件夹保存已编译的 scala 模板)未使用新添加的模板进行更新。我昨天确实尝试调用play compile,它没有帮助。未编译来自新包的新模板。今天早上我叫play clean compileaaand...万岁!我确实得到了编译模板和丢失包的问题(不要忘记刷新 Eclipse 项目,强制它从文件系统更新现有项目结构。它喜欢缓存所有内容。)

Sorry for disturbing, seems like I wasn't attentive while reading documentation :(

抱歉打扰了,我在阅读文档时似乎没有专心:(

回答by Nick Cooper

The problem is that Eclipse isn't seeing the src_managed folder, which is dynamically updated by the play framework.

问题是 Eclipse 没有看到 src_managed 文件夹,它是由播放框架动态更新的。

Go to project → properties → java build path → libraries (it's a tab) → add external class folder

转到项目→属性→java构建路径→库(它是一个选项卡)→添加外部类文件夹

Then select the src_managed folder, which should be in the folder target->scala-x.x.x in the same directory as your project.

然后选择src_managed文件夹,它应该在你的项目所在目录下的target->scala-xxx文件夹中。

This will add src_managed to your build path, and Eclipse will now understand that these templates are valid.

这会将 src_managed 添加到您的构建路径中,Eclipse 现在将了解这些模板是有效的。

You may need to run 'play clean compile' in the play framework console You may then need to run project -> clean in eclipse

您可能需要在 play 框架控制台中运行“play clean compile”,然后您可能需要在 eclipse 中运行 project -> clean

回答by Al-Mothafar

In Play 2.5, I was able to fix this issue with:

在 Play 2.5 中,我能够通过以下方式解决此问题:

import the view:

导入视图:

import views.html.index;

Then inside the controller:

然后在控制器内部:

return ok(index.render("Hello"));

Something like this without complex problems, strange that using it like return ok(views.html.index.render("Hello")))was not working while importing then use it worked well.

像这样的东西没有复杂的问题,奇怪的return ok(views.html.index.render("Hello")))是在导入时使用它不起作用然后使用它运行良好。

Sure all answers here helpful as well, sometimes the issue simply is to clean and then compile, but even this not really solving issue all the time, regardless the IDE you are using, I was using CLI and was giving cannot find symbolerror as well.

当然这里的所有答案也很有帮助,有时问题只是清理然后编译,但即使这并没有真正解决问题,无论您使用的是哪种 IDE,我都在使用 CLI 并且也cannot find symbol出现错误。

回答by trupti rath

To resolve "package views.html doesn not exist" :

要解决“包 views.html 不存在”:

Run "sbt compile" or "sbt clean compile". That should create a folder structure in your project as target\scala xx\twirl\main\views.html

运行“sbt compile”或“sbt clean compile”。这应该在您的项目中创建一个文件夹结构作为 target\scala xx\twirl\main\views.html

回答by aaberg

As far as I can tell, you haven't got a package name etlworkflowseqnode! The correct way to import the list template, should be like this:

据我所知,您还没有包名称 etlworkflowseqnode!导入列表模板的正确方法,应该是这样的:

import views.html.list;

or, if you are going to have multiple views, you can import them all with a wildcard import.

或者,如果您要拥有多个视图,则可以使用通配符导入将它们全部导入。

import views.html.*;