Here's how. (I did this for a kodo plugin I'm finishing up)
/**
* Adds nessessary items to the classloader.
*
* @return ClassLoader original Classloader.
* @throws MojoExecutionException
*/
public ClassLoader setupClassloader()
throws MojoExecutionException
{
URLClassLoader loader = null;
ClassLoader originalLoader =
Thread.currentThread().getContextClassLoader();
URL[] urls = buildClassPathURLs();
loader = new URLClassLoader( urls, originalLoader );
Thread.currentThread().setContextClassLoader( loader );
printClassPath();
return originalLoader;
}
/**
* Build the array of URLs to add to new ClassLoader
*
* @return
* @throws MojoExecutionException
*/
private URL[] buildClassPathURLs()
throws MojoExecutionException
{
ArrayList urls = new ArrayList();
Iterator iter = resources.iterator();
try
{
//add the Resource locations as urls
while ( iter.hasNext() )
{
Resource resource = (Resource) iter.next();
urls.add( new URL( "file:///" + resource.getDirectory()
+ "/" ) );
}
//add the outputDirectory
// urls.add(new URL( "file:///" +
classDir.getAbsolutePath() + "/"
// ));
//add the extra files to classpath
if ( null != extraClassPathItems )
{
for ( int i = 0; i < extraClassPathItems.length; i++ )
{
urls.add( buildURL( extraClassPathItems[i] ) );
}
}
}
catch ( MalformedURLException e )
{
throw new MojoExecutionException( "Nested:", e );
}
//convert back to array
URL[] urlArray = (URL[]) urls.toArray( new URL[urls.size()] );
return urlArray;
}
-----Original Message-----
From: Jochen Wiedmann [mailto:[EMAIL PROTECTED]
Sent: Wednesday, December 14, 2005 7:57 AM
To: Maven Users List
Subject: Project dependencies and plugin classloaders
Hi,
I have a project (A) which uses the maven-jaxme-plugin. The plugin
allows to configure so-called factory chains. Think of them as plugins
for the plugin.
I have another project (B), which implements such a factory chain.
Project B is one of the dependencies of A. However, the plugin fails to
load the classes from B. In other words, the plugins classpath is
obviously different from the projects classpath.
Do I need to extend the plugins classpath? By looking at the projects
dependency list? If so, how do I do that?
Regards,
Jochen
--
Often it does seem a pity that Noah and his party did not miss the boat.
(Mark Twain)
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]