【发布时间】:2011-01-05 17:47:32
【问题描述】:
在我们的系统中,我们有一个插件机制允许我们在运行时实例化未知的类。
在类路径中提供目录或jar,系统能够探索包含的类,如果类实现了特定的接口,它可以被实例化并用作插件。
所有东西都打包成罐子,运行良好。但是,当尝试将其捆绑为 webstart 应用程序时,这种机制似乎失效了。
更具体地说,类的发现似乎不再起作用了:
public static Collection<String> getAllClassFiles()
{
Collection<String> all_files = new ArrayList<String>();
String pathSep = System.getProperty("path.separator");
String classpath = System.getProperty("java.class.path");
for (String path : classpath.split(pathSep))
{
File filepath = new File(path);
if (filepath.isDirectory())
{
all_files.addAll(dirContent(filepath));
}
else if (path.endsWith(".jar"))
{
JarFile jar;
try {
jar = new JarFile(filepath);
}
catch (IOException e) {
Log.warning("WARNING: " + filepath + " could not be opened!");
continue;
}
for (Enumeration<JarEntry> entries = jar.entries(); entries
.hasMoreElements();)
{
JarEntry entry = entries.nextElement();
if (entry.getName().endsWith(".class"))
all_files.add(entry.getName());
}
}
else if (path.endsWith(".class")) {
all_files.add(path);
}
else {
Log.warning("Warning: corrupt classpath entry: " + path);
}
}
return all_files;
}
所以......这在直接使用 jar 调用系统时有效......但不再使用 webstart,尽管所有 jar 都已签名并包含在内。
知道如何让它与 webstart 一起工作吗?
【问题讨论】:
-
没有错误...只是返回一个空列表
-
...显然,这是因为使用 java webstart 时类路径消失了。它只变成: java.class.path = /usr/lib/jvm/java-6-sun-1.6.0.06/jre/lib/deploy.jar 当我转储系统/部署属性时,我看不到任何痕迹“我的”类路径也没有原始 jar 的任何信息……那么,如何收集可用类的列表?
标签: java reflection jar java-web-start