Search code examples
javaapachemavenvelocity

Moved Velocity jar from Bundle-ClassPath to Import-Package(Plugin dependancies) in MANIFEST.MF Then what should be the place for .vm file?


Project structure As shown above the project structure. In code,

/* Define velocity engine and template */
VelocityEngine ve = new VelocityEngine();
ve.setProperty("resource.loader", "classpath");
ve.setProperty("classpath.resource.loader.class",ClasspathResourceLoader.class.getName());
ve.init();
Template t = ve.getTemplate("fileTemplates/DCM_Default.vm");

Previously, velocity.jar present in /lib folder. Hence, DCM_Default.vm had found.MENIFEST.MF had entry as below in classpath,

Bundle-ClassPath: ., lib/velocity-1.7-dep.jar

Now, velocity. jar removed from classpath and it is present in Plugin dependancies in MENIFEST.MF have below changes-

Import-Package: org.apache.velocity, org.apache.velocity.app, org.apache.velocity.context, org.apache.velocity.exception, org.apache.velocity.runtime, org.apache.velocity.runtime.resource.loader

I unable to find path where I have to put .vm because I faced below exception Caused by: org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'fileTemplates/DCM_Default.vm'.

can any one has any idea? Please suggest.


Solution

  • I found solution as below-

           //Define template location 
            Bundle bundle = FrameworkUtil.getBundle(getClass());
            URL fileUrl = FileLocator.toFileURL(FileLocator.find(bundle, new Path('fileTemplates/'), null));`
    
            /* Define velocity engine and template */
            VelocityEngine ve = new VelocityEngine();
            ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, fileUrl.getPath());
            ve.init();
            Template t = ve.getTemplate("DCM_Default.vm");
    

    In path we need absolute path of the folder which calculate at runtime. This is work in RCP client Plugin project.