简体   繁体   English

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

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

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; [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不存在[error] import views.html.etlworkflowseqnode.list; [error] [错误]
^ [error] D:\\ECLIPSE_WORKSPACES\\play2_apps\\etl_admin\\app\\controllers\\EtlWorkflowSeqNodeController.java:14: error: cannot find symbol ^ [错误] D:\\ ECLIPSE_WORKSPACES \\ play2_apps \\ etl_admin \\ app \\ controllers \\ EtlWorkflowSeqNodeController.java:14:error:找不到符号

[error] list.render(EtlWorkflowSeqNode.findTree(jobId)) [error] ^ [error] symbol: variable list [error] [error] list.render(EtlWorkflowSeqNode.findTree(jobId))[错误] ^ [错误]符号:变量列表[错误]
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 location:class EtlWorkflowSeqNodeController [error] 2 errors [error] {file:/ D:/ ECLIPSE_WORKSPACES / play2_apps / etl_admin /} etl_admin / compile:compile:javac return nonzero exit code [error]总时间:7 s,已完成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". 有这样的包,有名为“list”的模板。 我的日食 what do I do Wrong 我做错了什么

Omg, the problem was so easy! 哦,问题很简单! *classes_managed* (this folder keeps compiled scala templates) were not updated with newly added templates. * classes_managed *(此文件夹保存已编译的scala模板)未使用新添加的模板进行更新。 I did try to call play compile yesterday, it doesn't help. 我确实试着昨天打电话编译 ,它没有帮助。 New templates from new package were not compiled. 新包中的新模板未编译。 This morning I've called play clean compile aaand... hooray! 今天早上我打电话给干净的编译 aaand ...万岁! 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.) 我确实得到了编译模板和丢失包的问题消失了(不要忘记刷新Eclipse项目,强制它从文件系统更新exisitng项目结构。它喜欢缓存所有内容。)

Sorry for disturbing, seems like I wasn't attentive while reading documentation :( 抱歉令人不安,看起来我在阅读文档时并不专心:(

The problem is that Eclipse isn't seeing the src_managed folder, which is dynamically updated by the play framework. 问题是Eclipse没有看到src_managed文件夹,它由play框架动态更新。

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-xxx 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

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 symbol error as well. 当然这里的所有答案都很有用,有时问题只是清理然后编译,但即使这并不是真正解决问题,无论你使用的是什么IDE,我都在使用CLI并且给出了cannot find symbol错误的信息。 。

To resolve "package views.html doesn not exist" : 要解决“包view.html不存在”:

Run "sbt compile" or "sbt clean compile". 运行“sbt compile”或“sbt clean compile”。 That should create a folder structure in your project as target\\scala xx\\twirl\\main\\views.html 这应该在您的项目中创建一个文件夹结构作为目标\\ scala xx \\ twirl \\ main \\ views.html

As far as I can tell, you haven't got a package name etlworkflowseqnode! 据我所知,你还没有包名etlworkflowseqnode! The correct way to import the list template, should be like this: 导入列表模板的正确方法应该是这样的:

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.*;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM