Passionate Software.
April 25, 2006

A nice way to launch SWT applications

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.

Tags: programming