You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Nitesh Naveen <ni...@sonata-software.com> on 2005/04/13 07:52:32 UTC

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


RE: Path problem reading .vm file in WSAD

Posted by Tanveer Dhillon <ta...@secf.com>.
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