You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by "Jan Larsen (Informatik)" <jl...@dsb.dk> on 2006/09/25 13:24:28 UTC

[Maven 2] Differences between running a plugin project and running the resulting plugin

I have made a plugin that generates some source code using Velocity.
This plugin (generator-plugin) compiles, tests and deploys without
problems. In this process Velocity loads some templates and generates
the correct files. So far so good.
 
When I attempt to use the generator-plugin in another project however, I
get a strange error from Velocity:
 
org.apache.velocity.exception.ResourceNotFoundException: Unable to find
resource '/src/main/data/templates/parser/trafik_element.vm'
        at
org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(Re
sourceManagerImpl.java:458)
        at
org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(Res
ourceManagerImpl.java:341)
        at
org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.
java:831)
        at
org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.
java:813)
        at
org.apache.velocity.runtime.RuntimeSingleton.getTemplate(RuntimeSingleto
n.java:285)
        at
org.apache.velocity.app.Velocity.getTemplate(Velocity.java:469)
 
I have (of course) verified the paths and tried combinations of slash
and backslash as well as absolute paths and relative paths.
 
Another part of generator-plugin uses simple file loading (without
involving Velocity) and has no problems finding files.
 
It looks as if Velocitys ResourceManager (which is pretty abstract and
complicated) is somehow initialized differently when called from a
project using a plugin than when the plugin is tested in its own project
thus resulting in a missing ResourceLoader or some such.
 
Has anyone had similar problems?
Can anyone point me to a discription of the differences between how
plugins are loaded and how projects are loaded in maven?
Any other ideas?
 
Jan

Re: [Maven 2] Differences between running a plugin project and running the resulting plugin

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Jan,

> org.apache.velocity.app.Velocity.getTemplate(Velocity.java:469)

You are using the singleton instance to obtain your templates.  That
means, that if Velocty was init-ed before your plugin, those settings
will be used, even in your plugin.

The recommended way to use Velocity in such context is via the
VelocityEngine.  Search for "Separate Instance" in:

http://jakarta.apache.org/velocity/docs/developer-guide.html#To%20Singleton%20Or%20Not%20To%20Singleton...

Best regards,
-- Shinobu

--
Shinobu Kawai <sh...@gmail.com>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org