velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gupta, Arindam" <arindam_gu...@fanniemae.com>
Subject RE: Trouble Loading a Template from a WAR file - Velocity 1.4 - WLS 8.12
Date Tue, 15 Jun 2004 14:53:21 GMT
Brian,
I am looking it up as "PoolXML.vm" and as long as the ResourceLoader
gets it in the classpath it is OK. The code is just as simpele as this:

	static Template getJobRequestTemplate(String templateName) //I
pass "PoolXML.vm"
	{
		if (ve != null)
		{
			try
			{
				Template t =
ve.getTemplate(templateName);
				return t;
			}
			catch (Exception e)
			{
				logger.error(e);
			}
		}
		return null;
	}

I have not tried the other option but if the resource is in the
classpath it should work.
BTW, do you have the following in the velocity.properties:

.......
resource.loader = file
file.resource.loader.description = Velocity File Resource Loader
file.resource.loader.class =
org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
.......

AND are you initializing the Velocity engine with this properties file?

-AG

-----Original Message-----
From: Brian Utt [mailto:brian_utt@yahoo.com] 
Sent: Tuesday, June 15, 2004 10:42 AM
To: Velocity Users List
Subject: RE: Trouble Loading a Template from a WAR file - Velocity 1.4 -
WLS 8.12


Arindam,

I tried each of these (incorporated my application
into an EAR file and placing the template in the WEB-INF/classes
directory and using a jar file to store the templates in the WEB-INF/lib
directory) and both complain with the same message.  I would prefer to
still use the WAR file, and thus the WEB-INF/lib solution would be a
nice one to use.  How do you reference the template using that solution,
would I lookup "PoolXML.vm" or "/PoolXML.vm" or should both work?  

Thanks!
-brian


--- "Gupta, Arindam" <arindam_gupta@fanniemae.com>
wrote:
> I have had success with the following solutions:
> 
> 1. Deploy the template files outside the ear file
> (in my case the
> deployment unit is an ear file) in the
> WEB-INF/classes or
> 2. jar up the templates and place the jar file in
> the WEB-INF/lib
> 
> Hope this helps.
> 
> -AG
> 
> -----Original Message-----
> From: Brian Utt [mailto:brian_utt@yahoo.com]
> Sent: Tuesday, June 15, 2004 10:04 AM
> To: velocity-user@jakarta.apache.org
> Subject: Trouble Loading a Template from a WAR file
> - Velocity 1.4 - WLS
> 8.12
> 
> 
> I am having trouble using the Velocity 1.4 package
> and
> loading a template from a WAR file.  I can
> successfully use the package with a command line
> java application, but
> when I ported it into a servlet, I get the infamous
> "Unable to find
> resource..." message.
> 
> I have tried to load the template with a generic
> servlet as well as extending the VelocityServlet and
> I
> seem to be missing an important step.  My .vm
> Template
> files are in my deployed WAR file in the
> WEB-INF/classes "folder" and I am running on
> Weblogic
> 8.12.
> 
> Below is my servlet code:
> 
> _____________________________________
> 
> public class DataDownloadServlet 
>        extends VelocityServlet
> {
>   public Template handleRequest( 
>          HttpServletRequest request, 
>          HttpServletResponse response, 
>          Context context ) 
>   throws IOException, ServletException 
>   {
>     try
>     {
>       //get the pool number to extract the data for.
>       String[] reqVals = 
>         request.getParameterValues("pn");
> 
>       String uri = request.getRequestURI();
> 
>       List beans = 
>         InternetDataManager.process(reqVals);
> 
>       Template template = null;
>       String templateName = "";
> 
>      
> response.setContentType("application/vnd.xml");
>       templateName = "PoolXML.vm";
> 
>       try
>       {
>           template = getTemplate(templateName);
> 
>           context.put("pools", beans);
> 
>           mergeTemplate(template, context,
> response);
>       }
>       catch( ResourceNotFoundException rnfe )
>       {
>         // couldn't find the template
>         System.out.println("Template Not Found: " + 
>                             templateName + 
>                             ": " +
> rnfe.getMessage());
>         throw new ServletException(rnfe);
>       }
>       catch( ParseErrorException pee )
>       {
>         // syntax error : problem parsing the
> template
>         System.out.println("Prob Parsing template "+
>                             templateName + 
>                             ": " +pee.getMessage());
>         throw new ServletException(pee);
>       }
>       catch( Exception e )
>       {
>         System.out.println("Weird Problem: " + 
>                             e.getMessage());
>         throw new ServletException(e);
>       }
>     }
>     catch (Exception ex)
>     {
>       System.out.println("Caughted exception: " + 
>                           ex.getMessage());
>       ex.printStackTrace(System.out);
> 
>       throw new ServletException(ex);
>     }
>     return null;
>   }
> }
> 
> _____________________________________
> 
> 
> I have read about a velocity.properties file, but I
> have not used one on my command line app and I was
> hoping not to have to use one on the j2ee app, but I
> might very well be wrong about that.  Any assistance
> will be very much appreciated!
> 
> Thanks in advance!
> 
> -Brian
> 
> 
> 
> =====
> Debugging is twice as hard as writing the code in
> the first place.
> Therefore, if you write the code as cleverly as
> possible, you are, by
> definition, not smart enough to debug it.
> --Kernighan
> 
>
---------------------------------------------------------------------
> 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
> 
> 


=====
Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it. --Kernighan

---------------------------------------------------------------------
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