如何通过#include在Velocity宏中包含静态或上传的文件

And*_*zie 5 velocity

我试图通过在初始请求下载的HTML中嵌入一些CSS来优化一些移动网页(或更准确地说服务器请求的数量).

这些页面是从我们基于Vosao的CMS提供的,并使用Apache Velocity宏.

正如预期的那样,这很好.

<link rel="stylesheet" type="text/css" media="screen" href="/file/downloads/contact.css" 
Run Code Online (Sandbox Code Playgroud)

这失败了

<style>
#include( "/file/downloads/contact.css" )
</style>
Run Code Online (Sandbox Code Playgroud)

因为Velocity无法找到该文件,具有此输出

org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource '/file/downloads/contact.css'
Run Code Online (Sandbox Code Playgroud)

这在日志中

org.apache.velocity.runtime.log.CommonsLogLogChute log: ResourceManager : unable to find resource '/file/Downloads/contact.css' in any resource loader.
E 2012-06-20 13:59:19.688
org.apache.velocity.runtime.log.CommonsLogLogChute log: #include(): cannot find resource '/file/Downloads/contact.css', called at vm[line 7, column 3]
Run Code Online (Sandbox Code Playgroud)

我已经阅读了速度文档(关于资源ROOT属性),甚至花了一些时间在源代码上.我在加载时玩过那些属性....并且没有运气.

如何让Velocity在我的/ war目录中包含静态文件,或者从路径中包含它?

小智 3

我已经成功地使用了这样的方法:

<style type="text/css">
  #include("my/path/to/file/file.css")
</style>
Run Code Online (Sandbox Code Playgroud)

也许你的文件路径错误?