private void clear(Class<?> type, String fieldName) throws Exception { Field field = type.getDeclaredField(fieldName); field.setAccessible(true); Object instance = field.get(null); if (instance instanceof Set) { ((Set<?>) instance).clear(); } if (instance instanceof Map) { Map<?, ?> map = ((Map<?, ?>) instance); for (Iterator<?> iterator = map.keySet().iterator(); iterator.hasNext();) { Object value = iterator.next(); if (value instanceof Class && ((Class<?>) value) .getClassLoader() instanceof RestartClassLoader) { iterator.remove(); } } } }
private Throwable doStart() throws Exception { Assert.notNull(this.mainClassName, "Unable to find the main class to restart"); ClassLoader parent = this.applicationClassLoader; URL[] urls = this.urls.toArray(new URL[this.urls.size()]); ClassLoaderFiles updatedFiles = new ClassLoaderFiles(this.classLoaderFiles); ClassLoader classLoader = new RestartClassLoader(parent, urls, updatedFiles, this.logger); if (this.logger.isDebugEnabled()) { this.logger.debug("Starting application " + this.mainClassName + " with URLs " + Arrays.asList(urls)); } return relaunch(classLoader); }