0
votes

I've a javafx application which is run by web start. In my fx application, I try to load the classes using ClassLoader as in below code. The parameter passed is a package name like "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.

I'm using 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!.

Tried searching on net/googling but in vain. Checked http://lopica.sourceforge.net/faq.html#customcl as well and tried using URLClassLoader as suggested. But that didn't work as well (Though did not know what should be passed to the parameter 'urls')

Any help is much apreciated.

1
Try to log urls from resources.nextElement(). - talex
How to do that? I did it when the application is run through IDE. It gives me a file URL. But how about in web start? How to debug when the application is started through web start? If I use sysout will it be written to JWS console? - Sudheendra
I dont know about JWS console, But you alwais can log to file. Thre are lot of logging libraris like slf4j or log4j. - talex

1 Answers

0
votes

I think this works in IDE because your BIN/classes directory is used to get all the files. In Webstart-Mode, all your classes are inside JARs.