如何让 NVelocity 正确初始化?

发布于 2024-07-15 19:11:51 字数 702 浏览 6 评论 0原文

我无法让 NVelocity 初始化。 我不想做任何复杂的事情,所以如果它以默认值初始化就很好,但它甚至不会这样做。

所以

VelocityEngine velocity = new VelocityEngine();
ExtendedProperties props = new ExtendedProperties();
velocity.Init(props);

结果是:“似乎没有类被指定为 ResourceManager...”

VelocityEngine velocity = new VelocityEngine();
velocity.Init();

我可以找到关于属性应该是什么的宝贵文档,也找不到如何使用简单的默认值对其进行初始化的文档。 谁能指点一下资源吗?

很多页面都指向此页面:

http://www.castleproject.org/ other/nvelocity/usingit.html

但是此页面跳过了(看似)最重要的一点——如何设置属性以及将它们设置为什么。

我只想从文件加载一个简单的模板。

I can't get NVelocity to initialize. I'm not trying to do anything complicated, so it's just fine if it initializes at the defaults, but it won't even do that.

This:

VelocityEngine velocity = new VelocityEngine();
ExtendedProperties props = new ExtendedProperties();
velocity.Init(props);

Results in: "It appears that no class was specified as the ResourceManager..."

So does this:

VelocityEngine velocity = new VelocityEngine();
velocity.Init();

I can find precious little documentation on what the properties should be, nor how to get it to initialize with the simple defaults. Can anyone point to a resource?

A lot of pages point back to this page:

http://www.castleproject.org/others/nvelocity/usingit.html

But this page skips over the (seemingly) most important point -- how to set the properties and what to set them to.

I just want to load a simple template from a file.

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

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

发布评论

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

评论(2

執念 2024-07-22 19:11:51

这是我发现的——

我使用的是原始的 NVelocity 库,它自 2003 年以来就没有更新过。我认为这是一个死项目。

我切换到 Castle Project 版本,它更容易 - 事实上,它的运行方式与我链接到的页面上的示例非常相似。 它似乎为属性设置了智能默认值。 我可以在不设置任何属性的情况下初始化它,但模板目录默认为“.”,因此我通常会设置该目录(运行“init”之前进行)。

要获取正确的 DLL,您需要下载最新的 NVelocity 版本(在撰写本文时为 1.1)。

城堡项目下载页面

Here's what I found out --

I was using the original NVelocity library, which hasn't had an update since 2003. I think it's a dead project.

I switched to the Castle Project version, and it's much easier -- in fact, it runs much like the examples on the page I linked to. It seems to set intelligent defaults for properties. I can initialize it without any properties set, but the template directory defaults to ".", so I generally set that one (do it before running "init").

To get the correct DLL, you need to download the latest NVelocity release (as of this writing it's 1.1).

Castle Project Download Page

百变从容 2024-07-22 19:11:51

您需要在程序集中包含以下文件,并确保它们的类型设置为“资源”,

src\Runtime\Defaults\directive.properties

src\Runtime\Defaults\nvelocity.properties

则 ResourceLocator 将找到这些文件

src\Runtime\Resource\Loader\ResourceLocator.cs

如果您像我一样在 GetManifestResourceNames() 上遇到异常, 尝试运行 Dvsl,然后尝试修改 ResourceLocator 构造函数以捕获并忽略错误,因为所需的文件位于本地程序集中(如果您在上面包含它们),并且该异常仅由外部程序集引发(不知道为什么)。

    foreach(Assembly a in assemblies) {
        String prefix = a.FullName.Substring(0,a.FullName.IndexOf(",")).ToLower();
        try
        {
            String[] names = a.GetManifestResourceNames();
            foreach (String s in names)
            {
                if (s.ToLower().Equals(fn) || s.ToLower().Equals(prefix + "." + fn))
                {
                    this.filename = s;
                    assembly = a;
                    isResource = true;
                }
            }
        } catch {
        }
  }

You need to include the following files in your assembly, and make sure that their type is set to "Resource"

src\Runtime\Defaults\directive.properties

src\Runtime\Defaults\nvelocity.properties

These will then be found by ResourceLocator

src\Runtime\Resource\Loader\ResourceLocator.cs

If you get an exception on GetManifestResourceNames() as I did when trying to run Dvsl, then try modifying the ResourceLocator constructor to catch and ignore the error since the required files are in your local assembly (if you included them above) and the exception is only thrown by external assemblies (no idea why).

    foreach(Assembly a in assemblies) {
        String prefix = a.FullName.Substring(0,a.FullName.IndexOf(",")).ToLower();
        try
        {
            String[] names = a.GetManifestResourceNames();
            foreach (String s in names)
            {
                if (s.ToLower().Equals(fn) || s.ToLower().Equals(prefix + "." + fn))
                {
                    this.filename = s;
                    assembly = a;
                    isResource = true;
                }
            }
        } catch {
        }
  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文