A nice way to launch SWT applications

Torsten Uhlmann

Tue, 25 Apr 2006

Photo by Torsten Uhlmann


SWT (the low level GUI toolkit used by Eclipse and a lot of other Java based apps) needs platform dependent libraries (.dll on Windows and .so on Unix). Normally you have to tell Java where it will find those libs. This is another way to launch SWT applications without the need to set -Djava.library.path to Java or to put the libs into a system wide path. main() would look like this:

public static void main(String[] args) throws Exception { 
  URL[] urls = ; 
  File workDir = ; 
  ClassLoader cl = new SWTClassLoader(urls, workDir); 
  Class mainClass = cl.loadClass(); 
  Method main = mainClass.getMethod("main", new Class[] { String[].class }); 
  main.invoke(null, new Object[] { args }); 
}
SWTClassLoader Thanks to Peter Nehrer for this tip.