我的RCP对ClassLoad问题的解决,这是一个读jndi配置文件的方法。
private void intJNDI() {
ClassLoader cl = Thread.currentThread().getContextClassLoader(); //保存老的ClassLoader
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); //设置新的ClassLoader
IPath path = new Path("properties/jndi.properties");
URL url = AdminConsolePlugin.getDefault().find(path);
Properties p = new Properties();
try {
p.load(url.openStream());
String address = System.getProperty("jndi.address");
String port = System.getProperty("jndi.port");
if (address != null && !address.trim().equals("") && port != null && !port.trim().equals("")) {
p.remove("java.naming.provider.url");
p.setProperty("java.naming.provider.url", "jnp://" + address.trim() + ":" + port.trim());
}
AdminConsolePlugin.getDefault().setJNDIInitContext(new InitialContext(p));
} catch (Throwable e) {
throw new RuntimeException("Failed to connect to domain controller.", e);
} finally {
Thread.currentThread().setContextClassLoader(cl);//最后恢复成老的ClassLoader
}
}