作为War文件运行时找不到Json Views模板 [英] Json Views template not found when run as a war file
问题描述
我正在使用Grails的Json views插件.在开发中可以使用,但是当我将其作为jar文件运行时,它无法找到要渲染的模板/gson文件.我收到以下错误
I am using Json views plugin of grails. Which works in development, but when I run it as a jar file, it is not able to find the templates/gson files for rendering. I get the following error
//code
def template = jsonViewTemplateEngine.resolveTemplate(<path to template>)
def writable = template.make(kase: kase)
//exception
Cannot invoke method make() on null object. Stacktrace follows:
java.lang.NullPointerException: Cannot invoke method make() on null object
我们正在使用的Json Views是我们正在开发的内联插件的一部分.我们创建的jar也使用该内联插件运行(使用gradle包装器实现)
Json Views we are using are a part of a inline plugin we are developing. Jar we create also runs with that inline plugin (implemented using gradle wrapper)
有什么想法/建议吗?
环境: 谷物-3.2.0 Groovy-2.4.7 Json-Views插件-1.1.1
Environment: Grails - 3.2.0 Groovy - 2.4.7 Json-Views plugin - 1.1.1
推荐答案
视图已预编译为可通过Gradle和compileGsonViews
任务进行部署的类.默认情况下,这是使用project.name
设置完成的.
Views are pre-compiled into classes for deployment via Gradle and the compileGsonViews
task. This is done using the project.name
setting by default.
您会在build/main/gson-classes
目录中注意到所生成的类.例如,如果您的应用程序名称为foo
,则将具有类似foo_book_show_gson.class
的类,其中foo_
部分被视为程序包"名称.
You will notice in the build/main/gson-classes
directory the classes that are produced. For example if your application name is foo
you will have classes like foo_book_show_gson.class
where the foo_
part is considered the "package" name.
在运行时.包名称,用于解析根据grails-app/conf/application.yml
中的info.app.name
设置计算的视图.
At runtime. The package name to use to resolve views calculated from the info.app.name
setting in grails-app/conf/application.yml
.
这意味着,如果在Gradle中您的project.name
评估为foo
,并且application.yml
中的设置也是foo
,那么一切都很好.这是最常见的情况,因为通常您的应用程序名称在两个地方都是相同的.
What this means is that if in Gradle your project.name
evaluates to foo
and the setting in application.yml
is also foo
then all is well. This is the most common case as typically your application name is the same in both places.
如果info.app.name
和Gradle project.name
不匹配,则会出现视图无法解析的问题.
If info.app.name
and the Gradle project.name
don't match up you can get the problem where views don't resolve.
您有两个选择可以解决此问题.一种是修改build.gradle
以显式指定程序包名称:
You have two options to fix this. One is to modify build.gradle
to explicitly specify the package name:
compileGsonViews.packageName = 'foo'
然后确保info.app.name
与该值匹配.
Then make sure info.app.name
matches that value.
第二个选项是重命名项目目录,以便info.app.name
和project.name
对齐.
The second option is rename your project directory so that info.app.name
and project.name
align.
这篇关于作为War文件运行时找不到Json Views模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!