我的应用程序在主应用程序的一个文件夹中插入了jars。
src
app_package
modules //plug in jars located here我的问题是我不能将这些jar作为文件,因为当主应用程序转换为jar时,您就不能拥有文件对象。目前,我正试图使用InputStream来获取这些jars。是否有一种方法可以使用输入流获取位于模块文件夹中的所有jars的urls?
更新
我使用来加载jar文件。首先,我将所有jar文件加载到文件对象中:
File modules = new File("modules");
File[] fileList = providerFiles.listFiles(new FileFilter() {
public boolean accept(File file) {
return file.getPath().toLowerCase().endsWith(".jar");
}
});下一步是使用以下方法获取urls:
URL[] urls = new URL[fileList.length];
for (int i = 0; i < fileList.length; i++)
urls[i] = fileList[i].toURI().toURL();
ucl = new URLClassLoader(urls); 我的问题是,我意识到在访问jar文件时应该使用getResource()。但是我所能做的就是
URL url = getClass().getResource(directory);
InputStream inputStream = url.openConnection().getInputStream();我不知道如何使用输入流来获取所有jars的urls。
发布于 2014-02-04 16:06:44
这还不完全清楚,但听起来好像在jar文件中有jar文件。对吗?如果是这样的话,那是一个非常非正统的部署。
如果要列出zip/jar文件中的文件,可以使用ZipInputStream
https://stackoverflow.com/questions/21556736
复制相似问题