Im working on a code generator, building upon Velocity. I have a problem. The
code generator needs to be able to change the "velocimacro.library" (or be
left out) every time the Velocity is initialized. 

The file macro.vm looks like this: 
#macro(hello) 
Hello!! 
#end 

The file hello.vm looks like this: 
#hello() 

When I run the code, it successfully creates the file Hello.txt with the
content: 
Hello!! 

But when I activate the first line "//init(null)" the macro is not
recognized, and the output of Hello.txt is: 
#hello() 

The code looks like this (it is just an example to show the problem): 

        public static void main(String args[]) { 
                //init(null); 
                init("uparser/template/java/macro.vm"); 
                VelocityContext velocityContext = new VelocityContext(); 
                
                String filename = "C:/project/vgen/tmp/Hello.txt"; 
                BufferedWriter out = null; 
                String templateFile = "uparser/template/java/hello.vm"; 
                
                try { 
                        Template template =
Velocity.getTemplate(templateFile); 
                        out = new BufferedWriter(new OutputStreamWriter(new
FileOutputStream(filename))); 

                        if (template != null) { 
                                template.merge(velocityContext, out); 
                        } 
                } catch (Exception e) { 
                        e.printStackTrace(); 
                } finally { 
                        if (out != null) { 
                                try { 
                                        out.flush(); 
                                        out.close(); 
                                } catch (IOException e) { 
                                        e.printStackTrace(); 
                                } 
                        } 
                } 
        } 
        
        public static void init(String macrosTemplateFile) { 
                Properties properties = new Properties(); 

                if (macrosTemplateFile != null) { 
                        properties.put("velocimacro.library",
macrosTemplateFile); 
                } 
                
                properties.put("file.resource.loader.path",
"C:/Source/Workspace33/vgen/projects"); 
                
                try { 
                        Velocity.init(properties); 
                } catch (Exception e) { 
                        System.out.println(e.toString()); 
                        return; 
                } 
        } 

Any ideas? 

BR, 
Jocke 


-- 
View this message in context: 
http://www.nabble.com/Macros-does-not-work-when-running-init%28%29-%2B-init%28properties%29-tp16521907p16521907.html
Sent from the Velocity - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to