我是一个由web start运行的javafx应用程序。在我的fx应用程序中,我尝试使用ClassLoader加载类,如下面的代码所示。传递的参数是一个包名,如" com.example.project.abcd"
public final static List<Class<?>> find(final String scannedPackage)
{
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
final String scannedPath = scannedPackage.replace(DOT, SLASH);
final Enumeration<URL> resources;
try {
resources = classLoader.getResources(scannedPath);
} catch (IOException e) {
throw new IllegalArgumentException(String.format(BAD_PACKAGE_ERROR, scannedPath, scannedPackage), e);
}
final List<Class<?>> classes = new LinkedList<Class<?>>();
while (resources.hasMoreElements()) {
final File file = new File(resources.nextElement().getFile());
classes.addAll(find(file, scannedPackage));
}
return classes;
}
现在我无法获得所有课程内容&#34; com.example.project.abcd&#34;当我通过java web start运行它时,但是通过IDE运行正常。
我正在使用JDK 7,JavaFX 2。
根据http://docs.oracle.com/javase/7/docs/technotes/guides/javaws/developersguide/faq.html#s211 Thread.currentThread()。getContextClassLoader()应该可以正常工作但不是!。
尝试搜索网络/谷歌搜索但徒劳无功。检查http://lopica.sourceforge.net/faq.html#customcl并尝试使用URLClassLoader。但这并没有起作用(虽然不知道应该将什么传递给参数&#39; urls&#39;)
任何帮助都是非常有用的。
答案 0 :(得分:0)
我认为这适用于IDE,因为您的BIN / classes目录用于获取所有文件。 在 Webstart-Mode 中,所有类都在JAR中。