我在Java編程幾周後嘗試從類路徑之外的文件夾中獲取pentao報告定義,但迄今未成功。Java從類路徑之外加載資源(pentaho)
下成功加載來自包含在類路徑中的文件夾中的定義,但我無法弄清楚如何從一個絕對路徑得到它的類路徑之外:
// Parse the report file
final URL reportDefinitionURL = classloader.getResource("some/path/inclass/Sample1.prpt");
final ResourceManager resourceManager = new ResourceManager();
final Resource directly = resourceManager.createDirectly(reportDefinitionURL, MasterReport.class);
return (MasterReport) directly.getResource();
我不知道如果這是Pentaho的專用或通用的Java問題,但我怎麼能得到基於未位於如
"/usr/share/pentaho/Sample1.prpt" ?
我已經嘗試了本類路徑的絕對路徑(Linux版)上的文件的定義:
File file = new File("/usr/share/pentaho/");
URL url = file.toURI().toURL();
URL[] urls = new URL[]{url};
ClassLoader cl = new URLClassLoader(urls);
final URL reportDefinitionURL = cl.getResource("Sample1.prpt");
我也曾嘗試包括在運行的外部路徑但這似乎並沒有工作,要麼:
java -cp ./lib/*:/usr/share/pentaho/*.prpt ...
任何幫助是非常感謝!