0
在Java中,我可以在類路徑中的某些資源的多個實例,並因此訪問它們:加載資源ME
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Enumeration<URL> resources = loader.getResources("META-INF/services/myService.properties");
while(resources.hasMoreElements()){
URL resource = resources.nextElement();
// process each resource here
}
這允許使用的服務提供者接口,多個地方通過將額外的jar放入類路徑中,實現可以在運行時提供。
在Java ME中是否有與此相當的內容?
[更新2011年四月11]
如果我能以某種方式得到的classpath中的jar文件的列表,我很可能只是通過網址連接器是這樣的:
String [] jarFiles = ... // somehow I got this
for(int i = jarFiles.length-1; i >= 0; i--){
String url = "jar:file:"+jarFiles[i]+"!/META-INF/services/myService.properties";
InputStream in = Connector.openInputStream(url);
//process each resource here
}
任何想法如何在J2ME的類路徑中獲取所有jar文件?
你需要什麼.jars? – ThomasRS 2011-04-12 20:16:21
我可以使用System.getProperty(「java.class.path」)在J2SE中獲得類路徑 - 我將測試我是否可以在JME中執行此操作。 – tofarr 2011-04-13 10:00:49
這個屬性似乎不存在於JME中。任何人都知道是否有相同的東西? – tofarr 2011-04-13 10:14:49