I'd be happy not to use backslashes, except that in my case the path that created problems was given to me by Java's getAbsolutePath() method. Because I'm running under Windows, it returns a Windows path, using backslashes, as it should. Velocity should in turn be able to handle such a path because it is in fact a valid Windows path.
-----Original Message----- From: Gonzalo Diethelm [mailto:[EMAIL PROTECTED] Sent: Monday, September 03, 2007 5:49 AM To: Velocity Users List Subject: Re: UNC paths in Velocity Allow me to paste my very last reply to this list. Regardless of the '/' vs '\' issue, Velocity does have a very quirky way of handling backslashes... Best regards. I suggest you NEVER use the backslash character for path delimiters. As far as I know, C, C++, C# and Java all understand the forward slash as a path separator, with the benefits of portable code and not having to quote and re-quote the backslash. Therefore, try something like "//myserver/home/peter/myproj/template". On Fri, 2007-08-31 at 07:50 -0700, Peter Steele wrote: > Velocity does not seem to properly support UNC paths under Windows. I am > running from a network drive on a Vista box and want to point Velocity to a > location relative to my current dir to find my template files. I have code > similar to the following: > > > > String templateDir = new File("templates"); > > String absTemplateDir = templateDir.getAbsolutePath(); > > Velocity.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, > absTemplateDir); > > Velocity.init(); > > Template myTemplate = Velocity.getTemplate("my_template.vm"); > > > > The getTemplate call fails saying that it cannot find the file. The init call > explains why: it generates a log message similar to this: > > > > INFO: FileResourceLoader : adding path '\myserver\home\peter\myproj\template' > > > > The file path *should* be '\\myserver\home\peter\myproj\template', but > Velocity strips one of the leading backslashes. The original string is > correct that’s returned by getAbsolutePath, with four backslashes > representing two real backslashes: > > > > \\\\myserver\\home\\peter\\myproj\\template > > > > This is what I’d expect. This doesn’t seem to satisfy Velocity though. If I > manually set the string to > > > > \\\\\\\\\\myserver\\home\\peter\\myproj\\template > > > > this solves the problem. What I ended up doing though was this: > > > > String absTemplateDir = templateDir.getAbsolutePath().replace('\\', > '/'); > > > > This also works, so obviously the problem has something to do with > interpreting the leading backslash characters that represent the Windows UNC > path. This seems like a bug to me… > > > > > No virus found in this outgoing message. > Checked by AVG Free Edition. > Version: 7.5.484 / Virus Database: 269.13.1/981 - Release Date: 8/31/2007 > 6:13 AM > -- Gonzalo Diethelm [EMAIL PROTECTED] No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.484 / Virus Database: 269.13.3/986 - Release Date: 9/3/2007 9:31 AM No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.485 / Virus Database: 269.13.7/992 - Release Date: 9/6/2007 8:36 AM
