Yes, in fact the library I'm using (Spring-beandoc) defaults to the context 
classloader for looking up the mapping files. Since the context classloader is 
by default set to the application classloader, the plug-in is responsible for 
switching the classloader at runtime before calling the library.

This holds also true when calling other third-party libraries such as JDBC, 
Xerces, etc...

I don't know how maven2 works internally, but wouldn't it be a good idea to let 
maven2 internally switch the context classloader to the plugin classloader 
before the plug-in is called ?

Mojo mojo = ....

final Thread current = Thread.currentThread();
final ClassLoader oldLoader = current.getContextClassLoader();
try {
  current.setContextClassLoader(mojo.getClass().getClassLoader());
  mojo.execute();
}
catch (Exception e) {
  throw new MavenReportException("Unable to execute mojo: " + e.getMessage(), 
e);
}
finally {
  current.setContextClassLoader(oldLoader);
}

Regards,
Mario.

-----Original Message-----
From: Brett Porter [mailto:[EMAIL PROTECTED]
Sent: Fri 8/19/2005 12:41 PM
To: Maven Users List
Subject: Re: [m2] plugin classpath question
 
Was that necessary? I assume you now have BeanDocClient as a dep on
your plugin, which should make the classloader current anyway, without
switching the context class loader.

- Brett

On 8/19/05, Van Steenberghe Mario (GFDI) <[EMAIL PROTECTED]> wrote:
> Thanks.
> 
> In fact my plugin calls a library that loads some resources inside these 
> libraries, so I had to switch the context classloader as follows:
> 
> public void executeReport(final Locale locale) throws MavenReportException {
>   final Thread current = Thread.currentThread();
>   final ClassLoader oldLoader = current.getContextClassLoader();
> 
>   try {
>     current.setContextClassLoader(BeanDocClient.class.getClassLoader());
> 
>     // ... call library code here ...
>   }
>   catch (Exception e) {
>     throw new MavenReportException("Unable to generate beandoc: " + 
> e.getMessage(), e);
>   }
>   finally {
>     current.setContextClassLoader(oldLoader);
>   }
> }
> 
> Regards,
> Mario.
> 
> -----Original Message-----
> From: Brett Porter [mailto:[EMAIL PROTECTED]
> Sent: Fri 8/19/2005 11:01 AM
> To: Maven Users List
> Subject: Re: [m2] plugin classpath question
> 
> The plugin gets the plugin's dependencies, not the project's.
> 
> Also, it uses a separate class loader, so the system classpath only
> reflects what was used to bootstrap Maven (classworlds).
> 
> You can get the JARs for the project's artifacts using the
> ${project.artifacts} expression.
> 
> - Brett
> 
> On 8/19/05, Van Steenberghe Mario (GFDI) <[EMAIL PROTECTED]> wrote:
> > Hello,
> >
> > Is there anyone who knows how the classpath is defined when a maven2 
> > plug-in is run ?
> >
> > I expected that all the dependent jars, defined in my POM should be on the 
> > classpath, but when I print out the classpath inside my plug-in, I get:
> >
> > /**
> >  * @see 
> > org.apache.maven.reporting.AbstractMavenReport#executeReport(java.util.Locale)
> >  */
> >
> > public void executeReport(final Locale locale) throws MavenReportException {
> >   ...
> >   getLog().info("  - classpath   : " + 
> > System.getProperty("java.class.path"));
> >   ...
> > }
> >
> > output:
> >
> >   - classpath   : /opt/maven2-SNAPSHOT/core/boot/classworlds-1.1-alpha-2.jar
> >
> >
> > Thanks,
> > Mario.
> >
> >
> 
> ---------------------------------------------------------------------
> 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]
> 
>

---------------------------------------------------------------------
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]

Reply via email to