You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by pratibha shinagare <pr...@yahoo.com> on 2006/08/30 07:05:08 UTC

need Urgent Help

Hi
  I m pratibha
  I m using Velocity.
  In my debian machin i m having JBoss-Eclipse ide,
  JBoss server, I installed velocity ide plugin for   
       Eclipse(plugins/org.apache.velocity_1.3.1)
  i m trying simple velocity application.
  i m getting following error- 

java.lang.NullPointerException
	at
org.apache.velocity.runtime.RuntimeInstance.setDefaultProperties(RuntimeInstance.java:295)
	at
org.apache.velocity.runtime.RuntimeInstance.initializeProperties(RuntimeInstance.java:423)
	at
org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:266)
	at
org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:441)
	at
org.apache.velocity.app.VelocityEngine.init(VelocityEngine.java:148)
	at hello.HelloWorld.main(HelloWorld.java:34)

My
 Two files are-
  HellowWorld.java
package hello;

import java.io.StringWriter;
import java.util.Properties;
//import java.io.*;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
//import org.apache.velocity.runtime.parser.*;

//import org.apache.velocity.exception.*;

/**
 *  Simple program to demonstrate the basic 
 *  technique of rendering a Velocity template
 */
public class HelloWorld
{
    public static void main( String[] args )
        
    {
        /*
         *  first, get and initialize a Velocity
engine
         */
         
        
        try{
        	
           VelocityEngine ve = new VelocityEngine();
           Properties p = new Properties();
           p.setProperty("file.resource.loader.path",
"/root/workspace/Test/hello");
           //Velocity.init( p );
        	     	
           ve.init(p);

        /*
         *  next, get the Template  
         */
        Template t =null;
        
        t = ve.getTemplate( "HelloWorld.vm" );

        /*
         *  create a context and add data  
         */

        VelocityContext context = new
VelocityContext();

        context.put("name", "World");

        /* 
         *  now render the template into a
StringWriter 
         */
         
        StringWriter writer = new StringWriter();

           t.merge( context, writer );

        /* 
         *  show the world 
         */

        System.out.println( writer.toString() );  
        }catch(java.lang.Exception le)
           {le.printStackTrace();}
         /*catch(Exception e)
         { e.printStackTrace();}*/
         
    }
}

and
HelloWorld.vm

code
Hello $name!  Welcome to Velocity!

Please reply

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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


Re: need Urgent Help

Posted by Felix Satyaputra <f_...@yahoo.co.uk>.
Hi Pratibha,

The problem is the full properties which is required
by the Velocity engine is not loaded. This is because
you supplied the properties yourself.

Best thing to do is to put velocity.properties at the
root of classpath, add your 
file.resource.loader.path property in the
velocity.properties, and then call Velocity.init() in
your code instead.

http://jakarta.apache.org/velocity/docs/developer-guide.html#Using%20Velocity%20In%20General%20Applications

Cheers,

Felix

--- pratibha shinagare <pr...@yahoo.com> wrote:

> Hi
>   I m pratibha
>   I m using Velocity.
>   In my debian machin i m having JBoss-Eclipse ide,
>   JBoss server, I installed velocity ide plugin for 
>  
>        Eclipse(plugins/org.apache.velocity_1.3.1)
>   i m trying simple velocity application.
>   i m getting following error- 
> 
> java.lang.NullPointerException
> 	at
>
org.apache.velocity.runtime.RuntimeInstance.setDefaultProperties(RuntimeInstance.java:295)
> 	at
>
org.apache.velocity.runtime.RuntimeInstance.initializeProperties(RuntimeInstance.java:423)
> 	at
>
org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:266)
> 	at
>
org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:441)
> 	at
>
org.apache.velocity.app.VelocityEngine.init(VelocityEngine.java:148)
> 	at hello.HelloWorld.main(HelloWorld.java:34)
> 
> My
>  Two files are-
>   HellowWorld.java
> package hello;
> 
> import java.io.StringWriter;
> import java.util.Properties;
> //import java.io.*;
> import org.apache.velocity.app.VelocityEngine;
> import org.apache.velocity.Template;
> import org.apache.velocity.VelocityContext;
> //import org.apache.velocity.runtime.parser.*;
> 
> //import org.apache.velocity.exception.*;
> 
> /**
>  *  Simple program to demonstrate the basic 
>  *  technique of rendering a Velocity template
>  */
> public class HelloWorld
> {
>     public static void main( String[] args )
>         
>     {
>         /*
>          *  first, get and initialize a Velocity
> engine
>          */
>          
>         
>         try{
>         	
>            VelocityEngine ve = new VelocityEngine();
>            Properties p = new Properties();
>           
> p.setProperty("file.resource.loader.path",
> "/root/workspace/Test/hello");
>            //Velocity.init( p );
>         	     	
>            ve.init(p);
> 
>         /*
>          *  next, get the Template  
>          */
>         Template t =null;
>         
>         t = ve.getTemplate( "HelloWorld.vm" );
> 
>         /*
>          *  create a context and add data  
>          */
> 
>         VelocityContext context = new
> VelocityContext();
> 
>         context.put("name", "World");
> 
>         /* 
>          *  now render the template into a
> StringWriter 
>          */
>          
>         StringWriter writer = new StringWriter();
> 
>            t.merge( context, writer );
> 
>         /* 
>          *  show the world 
>          */
> 
>         System.out.println( writer.toString() );  
>         }catch(java.lang.Exception le)
>            {le.printStackTrace();}
>          /*catch(Exception e)
>          { e.printStackTrace();}*/
>          
>     }
> }
> 
> and
> HelloWorld.vm
> 
> code
> Hello $name!  Welcome to Velocity!
> 
> Please reply
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam
> protection around 
> http://mail.yahoo.com 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> velocity-user-help@jakarta.apache.org
> 
> 



		
___________________________________________________________ 
Now you can scan emails quickly with a reading pane. Get the new Yahoo! Mail. http://uk.docs.yahoo.com/nowyoucan.html

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