我想获取可以在这些 jar 中搜索 .class 文件的所有 jar 路径。我编写了一个函数来搜索 App 主文件夹下的所有 jar,但遇到了一个问题——一些 jar 包存在但已过时,OSGi 未使用,例如。xxxx_1.0.0.jar 和 xxxx_1.2.0.jar 都存在,但 OSGi 只使用了 1.2.0。如果我在主文件夹中搜索,其中是否会出现在结果列表中。
那么有没有办法获取 OSGi 使用的所有 jar 文件?然后我可以过滤掉没有使用的jar文件。谢谢
补充: 我尝试使用这种方式获取所有Bundles的绝对URL,但是失败了:
StringBuffer sb = new StringBuffer();
Bundle[] bundles = com.ibm.director.services.storage.debugtool.Activator.context.getBundles();
for (Bundle bundle : bundles) {
java.net.URL url = bundle.getClass().getProtectionDomain().getCodeSource().getLocation();
sb.append("File:" + url.getFile() + ", Path:" + url.getPath() + "\n");
}
但是下面的输出重复了一百次:
File:/opt/ibm/director/lwi/runtime/core/eclipse/plugins/org.eclipse.osgi_3.4.3.R34x_v20081215-1030-RCP20120203-1500.jar
File:/opt/ibm/director/lwi/runtime/core/eclipse/plugins/org.eclipse.osgi_3.4.3.R34x_v20081215-1030-RCP20120203-1500.jar,
File:....
使用的 bundle 数量是:588,可能是正确的,我们可以从 API 获得绝对的 Bundles 路径,但为什么它们都一样?我怎样才能得到真正的路径?