[英]load class from another class within same jar in java web start fails
I've a javafx application which is run by web start. 我有一个通过Web Start运行的javafx应用程序。 In my fx application, I try to load the classes using ClassLoader as in below code.
在我的fx应用程序中,我尝试使用ClassLoader加载类,如下面的代码所示。 The parameter passed is a package name like "com.example.project.abcd"
传递的参数是程序包名称,例如“ 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;
}
Now I'm not able to get all the classes present inside "com.example.project.abcd" package when I run it thru java web start but through IDE it is working fine. 现在,我无法通过Java Web Start运行“ com.example.project.abcd”包中的所有类,但通过IDE可以正常运行。
I'm using JDK 7, JavaFX 2. 我正在使用JDK 7,JavaFX 2。
As per http://docs.oracle.com/javase/7/docs/technotes/guides/javaws/developersguide/faq.html#s211 Thread.currentThread().getContextClassLoader() should work fine but it is not!. 按照http://docs.oracle.com/javase/7/docs/technotes/guides/javaws/developersguide/faq.html#s211 Thread.currentThread()。getContextClassLoader()应该可以,但事实并非如此!
Tried searching on net/googling but in vain. 尝试通过网络/谷歌搜索,但徒劳无功。 Checked http://lopica.sourceforge.net/faq.html#customcl as well and tried using URLClassLoader as suggested.
还检查了http://lopica.sourceforge.net/faq.html#customcl并尝试按建议使用URLClassLoader。 But that didn't work as well (Though did not know what should be passed to the parameter 'urls')
但这并没有效果(尽管不知道应将什么传递给参数“ urls”)
Any help is much apreciated. 任何帮助都非常感谢。
I think this works in IDE because your BIN/classes directory is used to get all the files. 我认为这在IDE中有效,因为您的BIN / classes目录用于获取所有文件。 In Webstart-Mode , all your classes are inside JARs.
在Webstart-Mode中 ,所有类都在JAR内部。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.