![](/img/trans.png)
[英]bnd - Make resulted MANIFEST.MF to have one line per Bundle-ClassPath and RequireBundle entries
[英]Moved Velocity jar from Bundle-ClassPath to Import-Package(Plugin dependancies) in MANIFEST.MF Then what should be the place for .vm file?
/* 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");
以前,/ lib文件夾中存在velocity.jar。 因此,找到了DCM_Default.vm。MENIFEST.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
我無法找到必須放入.vm的路徑,因為我遇到以下異常原因:org.apache.velocity.exception.ResourceNotFoundException:無法找到資源'fileTemplates / DCM_Default.vm'。
有人有什么主意嗎? 請提出建議。
如果使用ClasspathResourceLoader,則在運行時必須具有一個包含fileTemplates / DCM_Default.vm的jar。 將其放在src目錄下並不能保證它是類路徑的一部分,它取決於您的IDE(哪個文檔應該告訴您如何執行此操作)。
如果您知道通往模板的絕對路徑,則也可以使用FileResourceLoader。
由於您符合Maven項目,因此Velocity文件應位於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");
我發現解決方案如下-
//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客戶端插件項目中有效。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.