0

I am using the load an appropriate SWT library dynamically using the code in here .

Method addUrlMethod = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
addUrlMethod.setAccessible(true);
....
URL swtFileUrl = new URL("rsrc:" + swtFileName);
addUrlMethod.invoke(classLoader, swtFileUrl);

Now just for experiment I change swt_win32_x86.jar file into an empty file. But line "addUrlMethod.invoke(classLoader, swtFileUrl);" does not throw any kind of exception.

Why is it so? And how can check whether the swtFileName is a valid SWT library file or not?

Community
  • 1
  • 1
Nikolay Kuznetsov
  • 9,467
  • 12
  • 55
  • 101

1 Answers1

1

Why is it so?

If you look at URLClassLoader.addURL, it only adds the argument to the list of URLs to search.

And how can check whether the swtFileName is a valid SWT library file or not?

Try to load a class which should be there:

try {
    classLoader.loadClass("org.eclipse.swt.SWT");
} catch (ClassNotFoundException e) {
    ...
}
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487