Benson Margulies wrote:
> I find myself looking to create a plugin where, as part of execution,
> it wants to create a classpath composed of the declared dependencies.
> Can anyone suggest a model?
Not sure, which plugin I used to look this up, but I had once the need to
scan the compiled classes for annotations and to load them; I had to build
my own classloader:
================ %< =================
private ClassLoader getCompilationClassLoader() throws
DependencyResolutionRequiredException
{
final Log log = getLog();
@SuppressWarnings("unchecked")
final List<String> classpathElements =
project.getCompileClasspathElements();
final List<URL> urls = new ArrayList<URL>();
for (final String classpathElement : classpathElements) {
try {
final URL url = new File(classpathElement).toURI().toURL();
if (log.isDebugEnabled()) {
log.debug("Add to compilation classpath: " + url.toString());
}
urls.add(url);
} catch (final MalformedURLException e) {
log.warn("Cannot convert strange class path element into URL: " +
classpathElement);
}
}
return new URLClassLoader(urls.toArray(new URL[urls.size()]),
Thread.currentThread().getContextClassLoader());
}
================ %< =================
- Jörg
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]