As to not contribute to the black-holiness that is this mailing list, here's
the solution that worked for me:

Added the following parameter to my Mojo:
    /**
     * @parameter expression="${project.runtimeClasspathElements}"
     * @readonly
     */
    private List<String> runtimeClasspathElements;

________________________________________________
Added the following methods to my Mojo:

    private ClassLoader createClassLoaderForProjectDependencies() throws
MojoExecutionException {
        URL[] urls = buildURLs();
        return new URLClassLoader(urls, this.getClass().getClassLoader());
    }

    private URL[] buildURLs() throws MojoExecutionException {
        List<URL> urls = new
ArrayList<URL>(runtimeClasspathElements.size());
        for (String element : runtimeClasspathElements) {
            try {
                urls.add(new File(element).toURI().toURL());
            } catch (MalformedURLException e) {
                throw new MojoExecutionException("Unable to access project
dependency: "+element, e);
            }
        }
        return urls.toArray(new URL[urls.size()]);
    }

_____________________________________________________________
Then I added the following to the top of my execute method:

        // Create a custom class loader to get the project classes and
dependencies
        final ClassLoader projectLoader =
createClassLoaderForProjectDependencies();


>From there I passed projectLoader to the library classes that already
existed to compile templates in my language for me.  Luckily they were
already setup to accept an alternate ClassLoader.  For that reason, your
mileage my vary and you may need to try and pass it to
Thread.currentThread().setContextClassLoader(ClassLoader) though I tried
that and it did not work for me.



jaxzin wrote:
> 
> I'm writing a plugin to precompile templates for a language similar to
> JSP.  The plugin needs the dependencies and compiled classes of the
> project its running in.  Does anyone have an example of how to add the
> containing project's dependencies and target/classes directory to the
> classpath of the plugin?
> 

-- 
View this message in context: 
http://www.nabble.com/Adding-project-dependencies-and-generated-classes-to-classpath-of-my-plugin-tp18624435p18643692.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to