代码之家  ›  专栏  ›  技术社区  ›  Aditi

将Velocity jar从包类路径移动到清单中的导入包(插件依赖项)。那么这个地方应该是做什么的呢。vm文件?

  •  0
  • Aditi  · 技术社区  · 8 年前

    Project structure 在代码中,

    /* 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");
    

    以前是速度。jar存在于/lib文件夹中。因此,DCM_默认。vm已经找到了。梅尼费斯特。MF在类路径中有如下条目,

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

    现在,速度。jar已从类路径中删除,并且它存在于MENIFEST中的插件依赖项中。MF有以下变化-

    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

    3 回复  |  直到 8 年前
        1
  •  0
  •   Claude Brisson    8 年前

    如果您使用ClasspathResourceLoader,那么在运行时您必须有一个包含fileTemplates/DCM\u默认值的jar。vm。将其放在src目录下并不能保证它是类路径的一部分,这取决于您的IDE(哪些文档应该告诉您如何这样做)。

    如果知道模板的绝对路径,也可以使用FileResourceLoader。

        2
  •  0
  •   soorapadman    8 年前

    resources 文件夹

    你的结构应该是这样的 src-->main-->resources-->fileTemplates

    velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "class,file");
    velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.Log4JLogChute");
    velocityEngine.setProperty("runtime.log.logsystem.log4j.logger", "VELLOGGER");
    velocityEngine.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
    velocityEngine.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.NullLogSystem");
    
        3
  •  0
  •   Aditi    8 年前

    我找到了如下解决方案-

           //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");
    

    这是RCP客户端插件项目中的工作。