如何在不重新启动速度的情况下编辑 velocmacro?

发布于 2024-10-30 13:15:16 字数 419 浏览 5 评论 0原文

我的速度宏正在被缓存,我不希望它们......至少在开发过程中。

我已经在属性文件中设置了以下属性...

velocimacro.library.autoreload=true
file.resource.loader.cache=false
velocity.engine.resource.manager.cache.enabled=false

...但这似乎并没有达到目的

使用速度属性,如何配置速度以不缓存宏?

(我正在使用速度 1.6.4)

编辑:

我不认为该行...

velocity.engine.resource.manager.cache.enabled=false

...与速度相关

My velocity macros are being cached and I don't want them to be... not during development at least.

I've set the following properties in my properties file...

velocimacro.library.autoreload=true
file.resource.loader.cache=false
velocity.engine.resource.manager.cache.enabled=false

... but this doesn't seem to have done the trick

Using velocity properties, how can I configure velocity to not cache macros?

(I'm using velocity 1.6.4)

EDIT:

I don't think the line...

velocity.engine.resource.manager.cache.enabled=false

...is relevant to velocity

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

仅一夜美梦 2024-11-06 13:15:16

我在 NVelocity(C# 速度端口)方面也遇到了同样的问题。深入研究他们的来源,我发现全局名称空间中宏的重新加载是由以下属性控制的。

properties.SetProperty(RuntimeConstants.VM_PERM_ALLOW_INLINE_REPLACE_GLOBAL, true);

我还没有用速度对此进行测试,但查看了他们的 文档该属性存在并且似乎完全符合您的需要。

I have been having the same issue with NVelocity (C# port of velocity). Digging through their souce I found that the re-loading of the macros in the global name space are controlled by the following property.

properties.SetProperty(RuntimeConstants.VM_PERM_ALLOW_INLINE_REPLACE_GLOBAL, true);

I havn't tested this with velocity but looking at their documentation the property exists and seem to do exactly what you need.

当爱已成负担 2024-11-06 13:15:16

看来你不能做你想做的事。我可以重新加载宏定义的唯一方法是将它们放入自己的库文件中并设置 velocimacro.library.autoreload = true。

来自 http://velocity.apache.org/engine/devel/developer-guide .html

velocimacro.library = VM_global_library.vm

多值键。将接受 CSV 的值。 Velocity Runtime 引擎启动时要加载的 Velocimacro 库的文件名。所有模板都可以访问这些 Velocimacros。假定该文件相对于文件加载器资源路径的根目录。


velocimacro.library.autoreload = false

控制 Velocimacro 库自动加载。当设置为 true 时,将检查调用的 Velocimacro 的源 Velocimacro 库是否有更改,并在必要时重新加载。这使您可以更改和测试 Velocimacro 库,而无需重新启动应用程序或 servlet 容器,就像使用常规模板一样。此模式仅在资源加载器中关闭缓存时才有效(例如 file.resource.loader.cache = false )。此功能旨在用于开发,而不是用于生产。

Looks like you cant do what you want. The only way I could get macro definitions to reload is to put them in their own library file and set the velocimacro.library.autoreload = true.

From http://velocity.apache.org/engine/devel/developer-guide.html

velocimacro.library = VM_global_library.vm

Multi-valued key. Will accept CSV for value. Filename(s) of Velocimacro library to be loaded when the Velocity Runtime engine starts. These Velocimacros are accessable to all templates. The file is assumed to be relative to the root of the file loader resource path.


velocimacro.library.autoreload = false

Controls Velocimacro library autoloading. When set to true the source Velocimacro library for an invoked Velocimacro will be checked for changes, and reloaded if necessary. This allows you to change and test Velocimacro libraries without having to restart your application or servlet container, just like you can with regular templates. This mode only works when caching is off in the resource loaders (e.g. file.resource.loader.cache = false ). This feature is intended for development, not for production.

十二 2024-11-06 13:15:16

如果宏不在速度库中而仅在某个模板文件中,我不确定这是否可行。

但是,在这种情况下,如果您只是想让开发更容易,您可以重命名宏(通过执行查找/替换全部,然后在末尾添加一个数字或其他内容)。然后您应该能够立即看到变化。您只需要记住完成后将其重命名回原来的名称即可!

I'm not sure this is possible if the macros are not in a velocity library and just in some template file.

However, in this case, if you just want to make development easier, you can just rename the macro (by doing a find/replace all and just adding a number to the end or something). Then you should be able to see the change straight away. You just have to remember to rename it back to what it's supposed to be when your finished!

余罪 2024-11-06 13:15:16

您可能需要设置

file.resource.loader.modificationCheckInterval 

这告诉速度检查文件是否已更改的频率。我无法从文档中得知默认值是什么,但我们在开发环境中将默认值设置为 2。可能只是这个属性的默认值是一个很大的数字或小于 0,这本质上是关闭的,这意味着它永远不会检查宏文件中的更改。

You might need to set

file.resource.loader.modificationCheckInterval 

This tells velocity how often to check if the file has changed. I can't tell from the docs what the default is, but we have ours set to 2 in our dev env. It might just be that the default value for this prop is a high number or less than 0 which is essentially off, meaning it will never check for changes in your macro file.

甩你一脸翔 2024-11-06 13:15:16

您可能想使用#define 指令而不是#macro。这些参考文献可能会发生变化。
使用它,您还可以命名 VTL 代码块并根据需要调用它多次。
将宏参数定义为同一上下文中的变量,并在命名块中使用它们,就像它是宏一样。
两者都可以解决常见情况;但它们并不等同。
https://velocity.apache.org/engine/1.7/user- Guide.html#define

You may want to use the #define directive instead of #macro. Theses references can change.
With it you can also name a block of VTL code and call it how many times you need it.
Define the macro arguments as variables in the same context and use them within the named block as if it were a macro.
Both can solve common situations; but they are not equivalent.
https://velocity.apache.org/engine/1.7/user-guide.html#define

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文