velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ross Bamford <ross-...@synergix-systems.co.uk>
Subject RE: Path problem reading .vm file in WSAD
Date Wed, 13 Apr 2005 11:46:19 GMT
Hi,

Not sure if you already tried this, but you could use a ClassPath
resource loader here. If you configure that *after* the File loader,
it will load from file if it exists, or drop back to a default template,
which you just make available in your classpath.

:)

Ross

On Wed, 2005-04-13 at 11:52 +0530, Nitesh Naveen wrote:
> Ok... found a solution...
> Need to set the file resource loader path before initializing.
> Then it fetches from the web root.
> 
> 			Properties p = new Properties();
> 			p.setProperty("file.resource.loader.path", "/");
> 
> 			Velocity.init(p);
> 			template = Velocity.getTemplate("email.vm");
> 
> Thanks for all help.
> 
> Nitesh
> 
> -----Original Message-----
> From: Nitesh Naveen [mailto:nitesh.n@sonata-software.com] 
> Sent: Wednesday, April 13, 2005 11:40 AM
> To: Velocity Users List
> Subject: RE: Path problem reading .vm file in WSAD
> 
> That could be a stop-gap solution... would work when I run it as a Java
> Application.
> But the final thing I need to achieve is to use the same in the
> application project.
> i.e where exactly would it be searching in runtime...
> When I run it as part of the j2ee application, it seems to go search in
> the default runtime folder for WSAD.
> 
> Nitesh
> 
> -----Original Message-----
> From: Tanveer Dhillon [mailto:tanveer.dhillon@secf.com] 
> Sent: Wednesday, April 13, 2005 11:32 AM
> To: Velocity Users List
> Subject: RE: Path problem reading .vm file in WSAD
> 
> To get the template email.vm, give the path starting from src folder
> say for eg
> Velocity.getTemplate("src/email.vm")
> 
> -----Original Message-----
> From: Nitesh Naveen [mailto:nitesh.n@sonata-software.com]
> Sent: Wednesday, April 13, 2005 11:23 AM
> To: velocity-user@jakarta.apache.org
> Subject: Path problem reading .vm file in WSAD
> 
> 
> Hi,
> 
> I'm trying to develop some common code for creating emails from a
> generic template using Velocity.
> 
> I have created a Java project in WSAD which has a src and classes folder
> for the source and compiled code respectively. I created a java
> application which would get a template "email.vm" 
> public class UtilTest
> {
> 
> 	public static void main(String[] args)
> 	{
> 		testVelocity();
> 
> 
> 		
> 	}
> 	
> 	private static void testVelocity()
> 	{
> 		try
> 		{
> 			Velocity.init();
> 			Template template =
> Velocity.getTemplate("email.vm");
> System.out.println("template:"+template);
> 			VelocityContext context = new VelocityContext();
> 			context.put ("title","Title....");
> 			context.put ("body","body..");
> 			context.put ("activityname","name....");
> 			context.put ("activitydescription","desc....");
> 			context.put ("startdate","xx-xx-xxxx....");
> 			context.put ("enddate","xx-xx-xxxx....");
> 			context.put ("planneditem","item....");
> 			context.put ("scheme","PE....");
> 			context.put ("link","link");
> 			StringWriter message = new StringWriter();
> 			template.merge(context, message);
> 			System.out.println(message.toString());
> 		}
> 		catch (ResourceNotFoundException e)
> 		{
> 			e.printStackTrace();
> 		}
> 		catch (ParseErrorException e)
> 		{
> 			e.printStackTrace();
> 		}
> 		catch (Exception e)
> 		{
> 			e.printStackTrace();
> 		}		
> 	}
> }
> 
> Template email.vm was placed under src (gets copied to classes when
> compiled). I compiled and tried to run the application from WSAD, but
> this was giving me a resource not found exception
> 
> org.apache.velocity.exception.ResourceNotFoundException: Unable to find
> resource 'email.vm'
> 	at
> org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(Re
> sourceManagerImpl.java:501)
> 	at
> org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(Res
> ourceManagerImpl.java:384)
> 	at
> org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.
> java:814)
> 	at
> org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.
> java:796)
> 	at
> org.apache.velocity.runtime.RuntimeSingleton.getTemplate(RuntimeSingleto
> n.java:337)
> 	at
> org.apache.velocity.app.Velocity.getTemplate(Velocity.java:512)
> 	at
> com.sonata.cpgfwk.util.UtilTest.testVelocity(UtilTest.java:49)
> 	at com.sonata.cpgfwk.util.UtilTest.main(UtilTest.java:38)
> 
> I tried going through the command prompt to classes folder and tried
> running the application from there. Seems to work perfectly fine... but
> doesn't work when I run it throught WSAD.
> However with WSAD if I place the the email.vm file in the project base
> folder outside src/classes, WSAD is able to pick it up.
> 
> Has anyone faced this problem? Any solutions welcome...
> 
> Thanks in advance for any help,
> 
> Nitesh
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Mime
View raw message