配置Java HBS查找部分模板的位置

时间:2015-09-19 00:37:53

标签: java maven templates handlebars.js partials

简而言之,Java HBS(jknack.handlebars)正在寻找与父模板完全不同的目录中的部分模板。有没有人知道如何配置jknack.handlebars查找部分模板的位置?

我需要避免: createLayeredHtml中的错误..         com.github.jknack.handlebars.HandlebarsException:/com/XXX/YYY/inline@53ce2ca5.hbs:598:8:无法找到部分'/com/XXX/YYY/temp-templates/CarouselHeader.hbs' / EM>

这是父模板:

  <div data-module="{{type}}" data-module-id="{{module_id}}" class="slick-module athena-item-page-carousel">

{{> temp-templates/CarouselHeader}}

<div class="js-carousel-n-up carousel carousel-narrow carousel-banner carousel-n-up-responsive">
    {{> temp-templates/CarouselFirstTile}}

更新 我应该说,HBS正在寻找的默认位置是我的(请原谅我,如果这不是正确的术语)我的包在java中的主目录。它在/ src / main / java / com / company / project中查找。有没有办法把它指向/ src / main / resources?

这是完整的错误:

[ERROR] 2015-09-18 17:23:34.688 [main] 
Error in createLayeredHtml..
    com.github.jknack.handlebars.HandlebarsException: /com/XXX/YYY/inline@53ce2ca5.hbs:598:8: The partial '/com/XXX/YYY/temp-templates/CarouselHeader.hbs' could not be found
        at com.github.jknack.handlebars.internal.Partial.merge(Partial.java:142)
        at com.github.jknack.handlebars.internal.BaseTemplate.apply(BaseTemplate.java:128)
        at com.github.jknack.handlebars.internal.TemplateList.merge(TemplateList.java:61)
        at com.github.jknack.handlebars.internal.BaseTemplate.apply(BaseTemplate.java:128)
        at com.github.jknack.handlebars.internal.BaseTemplate.apply(BaseTemplate.java:115)
        at com.github.jknack.handlebars.Options.apply(Options.java:271)
        at com.github.jknack.handlebars.Options.fn(Options.java:237)
        at com.github.jknack.handlebars.Options.fn(Options.java:226)
        at com.github.jknack.handlebars.helper.IfHelper.apply(IfHelper.java:51)
        at com.github.jknack.handlebars.internal.Block.merge(Block.java:160)
        at com.github.jknack.handlebars.internal.BaseTemplate.apply(BaseTemplate.java:128)
        at com.github.jknack.handlebars.internal.TemplateList.merge(TemplateList.java:61)
        at com.github.jknack.handlebars.internal.BaseTemplate.apply(BaseTemplate.java:128)
        at com.github.jknack.handlebars.internal.BaseTemplate.apply(BaseTemplate.java:115)
        at com.github.jknack.handlebars.internal.ForwardingTemplate.apply(ForwardingTemplate.java:82)
        at com.github.jknack.handlebars.internal.ForwardingTemplate.apply(ForwardingTemplate.java:60)
        at com.XXX.YYY.utils.HandlebarUtils.render(HandlebarUtils.java:80)
        at com.XXX.YYY.AthenaLayeredAsset.createLayeredHtml(AthenaLayeredAsset.java:68)
        at com.XXX.YYY.AthenaSlickCarousel.generateNarrowCarouselHTML(AthenaSlickCarousel.java:27)
        at com.XXX.YYY.TestAthenaLayeredAsset.testNarrowCarouselSimple(TestAthenaLayeredAsset.java:387)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
        at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
        at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
        at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
        at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
        at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
        at org.testng.TestRunner.privateRun(TestRunner.java:767)
        at org.testng.TestRunner.run(TestRunner.java:617)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
        at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
        at org.testng.SuiteRunner.run(SuiteRunner.java:240)
        at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
        at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
        at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
        at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
        at org.testng.TestNG.run(TestNG.java:1057)
        at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
        at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
        at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
        at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:125)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

1 个答案:

答案 0 :(得分:0)

基本上,您需要确保模板位于类路径中,并确保TemplateLoader知道“部分”的位置。

很久以前就丢弃了这个错误,我终于想出了如何确保包含所有模板的目录都包含在类路径中。我确信不止一种方法可以做到这一点,而且maven专家可能知道一个更好的方法,但我用过:

http://maven.apache.org/surefire/maven-surefire-plugin/examples/configuring-classpath.html

然后为了确保你的TemplateLoader知道你的“部分”在哪里,你可以使用setPrefix

https://github.com/jknack/handlebars.java

或我们使用的版本在构造函数中有一个选项:

protected static final TemplateLoader loader =             新的ClassPathTemplateLoader(“/ partials /”);

非常感谢Roman和Tassos Bassoukos的暗示!!