You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Mark Lybarger <Ma...@CBC-Companies.com> on 2004/02/04 21:57:38 UTC

ResourceNotFoundException looking for template.

I'm looking to use velocity standalone in an application.  I have a velocity template file that is in the same directory as my class which is initializing velocity.  I'm getting a ResourceNotFoundException when i try to load the template.  Here's the code I'm using to initialize velocity and use it.  The line that blows up is the velocityEngine.getTemplate.  this class is a standalone application, but it's located w/i my WEB-INF/classes folder.  The template referenced below is also in the WEB-INF/classes folder (same subfolder as the class looking for the template).


Any suggestions would be most appreciated.  I'm currently using Turbine, and initializing that seems to work ok, but i don't need all that overhead.

Thanks!


        try
        {
            Properties properties = new Properties();
            
            properties.put("resource.loader", "class");
            properties.put("class.resource.loader.description","Template Class Loader");
            properties.put("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
            velocityEngine.init( properties );
            //Velocity.init(properties);
        } catch ( Exception e )
        {
            log.error( "Util.printReportItems() - error initializing velocity" + e );
        }
        
        for ( Iterator iter = itemList.iterator(  ); iter.hasNext(  ); )
        {
            try
            {
                ResponseRecord element = (ResponseRecord) iter.next(  );
                Context            context = new VelocityContext(  );
                context.put( "acdvResponseRecord", element );
                
                String historyStartDate = this.shiftResponsePaymentGrid( element );
                context.put( "ResponseRecord", element );
                context.put( "historyStartDate", historyStartDate );
                
                String ResponseRpt = velocityToHTML( velocityEngine, context, "ResponseReport.vm" );

....

    private String velocityToHTML( VelocityEngine velocityEngine, Context context, String templateName ) throws Exception
    {
        StringWriter   strWriter = null;
        BufferedWriter writer = null;
        Template       template = null;

        //	Get the velocity template and merge with the context
        template      = velocityEngine.getTemplate(templateName);
....

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.574 / Virus Database: 364 - Release Date: 1/29/2004
 


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