2

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.

Deane
  • 8,269
  • 12
  • 58
  • 108

2 Answers2

2

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

Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275
Deane
  • 8,269
  • 12
  • 58
  • 108
0

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 {
        }
  }
RAS
  • 8,100
  • 16
  • 64
  • 86